Write a program that prints a table indicating the number of occurrences of each alphabet
in the text entered as command line arguments.
#include <iostream>
using namespace std;
int main()
{
char str[100];
int i;
int freq[256] = {0};
cout<<"Enter the string: ";
gets(str);
for(i = 0; str[i] != '\0'; i++)
{
freq[str[i]]++;
}
for(i = 0; i < 256; i++)
{
if(freq[i] != 0)
{
cout<<"The frequency of "<<char(i)<<" is "<<freq[i]<<endl;
}
}
return 0;
}
0 Comments
Post a Comment