Advertisement
AedenCak3

C program to show the number of times different letters appear in a string

Dec 8th, 2021
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6.     char a[100];
  7.     int count=0;
  8.     int i,j;
  9.     printf("Enter any sentence:");
  10.  
  11.     gets(a);
  12.  
  13.     printf("Frequencies of letters in the input string:\n");
  14.  
  15.     for(i=0; i<strlen(a); i++)
  16.     {
  17.  
  18.         if(a[i]>='A' && a[i] <='Z'|| a[i]>='a' && a[i]<= 'z')
  19.         {
  20.             count=1;
  21.  
  22.         for(j=i+1; j<strlen(a); j++)
  23.             {
  24.                 if(toupper(a[i])==toupper(a[j]))
  25.                 {
  26.  
  27.                     a[j]=' ';
  28.                     count++;
  29.                 }
  30.             }
  31.  
  32.             printf("%c %c: %d\n ", toupper(a[i]),tolower(a[i]), count);
  33.         }
  34.  
  35.  
  36.     }
  37.  
  38.  
  39.  
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement