Advertisement
murad45

Programming task - 01

Apr 26th, 2021
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     char str[50];
  6.     int alphabets = 0;
  7.     int digits = 0;
  8.     int specialchar= 0;
  9.     int i = 0;
  10.  
  11.  
  12.     printf("Enter any string : ");
  13.     scanf("%s", &str);
  14.  
  15.     /*
  16.      * Check each character of string for alphabet, digit or special character
  17.      */
  18.     while(str[i]!='\0')
  19.     {
  20.         if((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
  21.         {
  22.             alphabets++;
  23.         }
  24.         else if(str[i]>='0' && str[i]<='9')
  25.         {
  26.             digits++;
  27.         }
  28.         else
  29.         {
  30.             specialchar++;
  31.         }
  32.  
  33.         i++;
  34.     }
  35.  
  36.     printf("Alphabets = %d\n", alphabets);
  37.     printf("Digits = %d\n", digits);
  38.     printf("Special characters = %d", specialchar);
  39.  
  40.     return 0;
  41. }
  42.  
  43.  
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement