i want to have a program to read a string and print the
frequency of each character and it should work in turbo c

Answers were Sorted based on User's Feedback



i want to have a program to read a string and print the frequency of each character and it should..

Answer / swarna sekhar dhar

#include<stdio.h>
#include <conio.h>
void main()
{
int a[26],i,l,j;
char s[180];
clrscr();
for(i=0;i<26;i++)
a[i]=0;
printf("enter a string: \n");
gets(s);
l=strlen(s);
for(i=0;i<l;i++)
{
for(j=0;j<26;j++)
{
if (s[i] == (j+66) || s[i] == (j + 96) )
a[j] += 1;
}
}
printf("charecter | Repetation \n");
for (j=0;j<26;j++)
{
printf("%c | %d \n ",j+64,a[j]);
}
getch();
}

Is This Answer Correct ?    11 Yes 7 No

i want to have a program to read a string and print the frequency of each character and it should..

Answer / rahul

#include<stdio.h>
#include <conio.h>
void main()
{
int a[26],i,l,j;
char s[180];
clrscr();
for(i=0;i<26;i++)
a[i]=0;
printf("enter a string: \n");
gets(s);
l=strlen(s);
for(i=0;i<l;i++)
{
for(j=0;j<26;j++)
{
if (s[i] == (j+65) || s[i] == (j + 97) )
a[j] += 1;
}
}
printf("charecter | Repetation \n");
for (j=0;j<26;j++)
{
printf("%c | %d \n ",j+65,a[j]);
}
getch();
}

Is This Answer Correct ?    4 Yes 6 No

i want to have a program to read a string and print the frequency of each character and it should..

Answer / shashi

33 45

Is This Answer Correct ?    0 Yes 5 No

Post New Answer

More C Interview Questions

what are the uses of structure?

7 Answers   HCL,


What are the keywords in c?

0 Answers  


Explain how are portions of a program disabled in demo versions?

0 Answers  


What are derived data types in c?

0 Answers  


Reverse the bit order in a single macro. eg. i/p = 10010101 --> o/p = 10101001

2 Answers  


what is the use of getch() function in C program.. difference b/w getch() and getche()??

29 Answers   HCL, IBM, Infosys, TCS, Wipro,


Given an array of characters, how would you reverse it? How would you reverse it without using indexing in the array?

1 Answers   Microsoft,


What is union in c?

0 Answers  


What are the uses of a pointer?

0 Answers  


Can you return null in c?

0 Answers  


How can I increase the allowable number of simultaneously open files?

1 Answers   CSC,


which of the following statements is incorrect a.typedef struct new{ int n1; char n2; } DATA; b.typedef struct { int n3; char *n4; }ICE; c.typedef union { int n5; float n6; } UDT; d.#typedef union { int n7; float n8; } TUDAT;

5 Answers   Assurgent, TCS,


Categories