Advertisement
Guest User

Untitled

a guest
Feb 15th, 2015
185
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. #include <ctype.h>
  3.  
  4. main(void){
  5.     int ch, coun1 = 0, coun2 = 0, coun3 = 0, sum1 = 0, sum2 = 0, sum3 = 0;
  6.     while((ch = getchar()) != '\n'){
  7.         if(isalpha((char)ch)){
  8.             if(isupper((char)ch)){
  9.                 coun1++;
  10.                 sum1 += ch;
  11.             }else{
  12.             coun2++;
  13.             sum2 += ch;
  14.             }
  15.         }else{
  16.             if(isdigit((char)ch)){
  17.                 coun3++;
  18.                 sum3 += ch;
  19.             }
  20.         }
  21.     }
  22.     printf("The average ascii value of the alpha numeric characters is %f\n", (float)(sum1+sum2+sum3) / (coun1+coun2+coun3));
  23.     printf("The average numeric character is %f\n", (float)sum3 / coun3);
  24.     printf("The average alpha character is %f\n", (float)sum2 / coun2);
  25.     printf("The average upper case character is %f\n", (float)sum1 / coun1);
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement