Advertisement
Dido09

C - Counting Letters

May 24th, 2022
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <string.h>
  2.  
  3. int main()
  4. {
  5.     char s[1000];
  6.     int  i, k, count=0, n, length;
  7.  
  8.     printf("Enter the string: ");
  9.     gets(s);
  10.  
  11.     for(length=0;s[length];length++);
  12.      n=length;
  13.  
  14.     for(i=0;i<n;i++)
  15.     {
  16.         count=1;
  17.         if(s[i])
  18.         {
  19.  
  20.           for(length=i+1;length<n;length++)
  21.           {
  22.  
  23.             if(s[i]==s[length])
  24.             {
  25.                  count++;
  26.                  s[length]='\0';
  27.             }
  28.           }
  29.           printf("%c = %d \n",s[i],count);
  30.        }
  31.     }
  32.     return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement