mhrabbi

P3. Program to count vowels, constant, digits, spaces

Jul 23rd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     char n[100];
  5.     int i,vowel=0,consonants=0,digit=0,space=0;
  6.  
  7.     printf("Enter a line: ");
  8.     gets(n);
  9.  
  10.     for(i=0; n[i]!='\0'; i++)
  11.     {
  12.         if(n[i]=='a' || n[i]=='e' || n[i]=='i'||n[i]=='o'|| n[i]=='u'||
  13.  
  14.                 n[i]=='A' || n[i]=='E' || n[i]=='I'||n[i]=='O'|| n[i]=='U')
  15.         {
  16.             vowel++;
  17.         }
  18.         else if(n[i]>='a'&& n[i]<='z'||n[i]>='A'&& n[i]<='Z')
  19.         {
  20.             consonants++;
  21.         }
  22.         else if(n[i]>='0'&& n[i]<='9')
  23.         {
  24.             digit++;
  25.         }
  26.         else if(n[i]==' ')
  27.         {
  28.             space++;
  29.         }
  30.  
  31.     }
  32.     printf("Vowel in the line is %d\n",vowel);
  33.     printf("Consonant in the line is %d\n",consonants);
  34.     printf("Digit in the line is %d\n",digit);
  35.     printf("Space in the line is %d\n",space);
  36.  
  37.     return 0;
  38.  
  39. }
Add Comment
Please, Sign In to add comment