Advertisement
FelipeNeto2

Readability

Apr 20th, 2020
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <string.h>
  4. #include <math.h>
  5.  
  6. int main(void){
  7.     string s = get_string("Text: ");
  8.     int cletra = 0, cpalavra = 1, cfrase = 0;
  9.     float L, S, x;
  10.  
  11.     //conta o total de letras
  12.     for(int i=0, n=strlen(s); i<n; i++){
  13.         if((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')){
  14.             cletra++;
  15.         }
  16.     }
  17.  
  18.     //conta o total de palavras
  19.     for(int i=0, n=strlen(s); i<n; i++){
  20.         if(s[i] == ' '){
  21.             cpalavra++;
  22.         }
  23.     }
  24.  
  25.     //conta o total de frases
  26.     for(int j=0, n=strlen(s); j<n; j++){
  27.         if((s[j] == '.') || (s[j] == '!') || (s[j] == '?')){
  28.             cfrase++;
  29.         }
  30.     }
  31.  
  32.     L = ((float) cletra/ (float) cpalavra)*100;
  33.     S = ((float) cfrase/ (float) cpalavra)*100;
  34.  
  35.     x = 0.0588 * (100 * (float) cletra / (float) cpalavra) - 0.296 * (100 * (float) cfrase / (float) cpalavra) - 15.8;
  36.  
  37.     if(x>=16){
  38.         printf("Grade 16+\n");
  39.     }else{
  40.         printf("Grade %i\n", (int) round(x));
  41.     }  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement