Write a C program to calculate the frequencies of different alphabets, present in a given string. The string of alphabets is to be taken as input from the keyboard.
#include<stdio.h>
#include<conio.h>
int frequency ( char str[], int j );
void main ( )
{
char str[70];
int i, freq, j;
clrscr ( );
printf("\n\n\n\t Enter a string of alphabets..:"); gets(str);
for ( j = 'a'; j <= 'z'; j++ )
{
freq = frequency ( str, j );
if ( freq != 0 )
{
printf("\n\n\t\t\t Frequency of %c = %d",j,freq);
}
freq = frequency ( str, j - 32 );
if ( freq != 0 )
{
printf("\n\n\t\t\t Frequency of %c = %d",j-32,freq);
}
}
getch();
}
int frequency ( char str[], int j )
{
int freq = 0, i;
for ( i = 0; str[i] != '\0'; i++ )
{
if ( str[i] == j )
{
freq++;
}
}
return freq;
}
Click here to contact us
#include<stdio.h>
#include<conio.h>
int frequency ( char str[], int j );
void main ( )
{
char str[70];
int i, freq, j;
clrscr ( );
printf("\n\n\n\t Enter a string of alphabets..:"); gets(str);
for ( j = 'a'; j <= 'z'; j++ )
{
freq = frequency ( str, j );
if ( freq != 0 )
{
printf("\n\n\t\t\t Frequency of %c = %d",j,freq);
}
freq = frequency ( str, j - 32 );
if ( freq != 0 )
{
printf("\n\n\t\t\t Frequency of %c = %d",j-32,freq);
}
}
getch();
}
int frequency ( char str[], int j )
{
int freq = 0, i;
for ( i = 0; str[i] != '\0'; i++ )
{
if ( str[i] == j )
{
freq++;
}
}
return freq;
}
Click here to contact us
No comments:
Post a Comment