Solved programming problem

Find the frequency of each character in ta string in C.

Source code

#include <stdio.h>

int main()

{

    char str[30];

    int x, len;

    int fre[26];

    printf("a
Please Enter any string: ");

    gets(str);

   for(len=0;str[len]!='';len++) ///counting the string length

    for(x=0; x<26; x++)

     {

        fre[x] = 0; ///saving a array for 26 alphabet and assign them as 0;

     }

    /// checking for all

    for(x=0; x<len; x++)

     {

         if(str[x]>='A' && str[x]<='Z') /// for uppercase

           {

           fre[str[x] - 65]++; /// saving them in a array

           }

        else if(str[x]>='a' && str[x]<='z')/// for lowercase

           {

            fre[str[x] - 97]++;  /// saving them in a array

           }

     }

    printf("a
Frequency of all characters in the given string: 
");

    for(x=0; x<26; x++)

     {

        if(fre[x] != 0) /// don't print those alphabet which don't have in the string

            {

            printf("'%c' = %d
", (x + 97), fre[x]);

            }

     }

    return 0;

}

Output

Please Enter any string: amsterdam

Frequency of all characters in the given string:

'a' = 2

'd' = 1

'e' = 1

'm' = 2

'r' = 1

's' = 1

't' =1

Join the discussion

Add your comment

2 previous comments

lautlew

f RBF decreases with decreasing RPP and 2 efficient medullary autoregulation equal to the cortical autoregulation reported in Mattson et al <a href=http://cialis.lat/discover-the-best-prices-for-cialis>cheapest cialis available</a>

pneussy

[url=https://newfasttadalafil.com/]where to buy cialis cheap[/url] Buy Generic Isotretinoin Internet Visa With Free Shipping Krcojt <a href=https://newfasttadalafil.com/>Cialis</a> Prix Viagra Pfizer Pharmacie En Merignac https://newfasttadalafil.com/ - buy generic cialis online safely