-
Notifications
You must be signed in to change notification settings - Fork 4
/
readability.c
47 lines (41 loc) · 891 Bytes
/
readability.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <cs50.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(void)
{
string text = get_string("Text: ");
int letters = 0, words = 1, sentences = 0;
for (int i = 0, n = strlen(text); i < n; i++)
{
char current = text[i];
if (isalpha(current))
{
letters++;
}
else if (current == ' ')
{
words++;
}
else if (current == '.' || current == '!' || current == '?')
{
sentences++;
}
}
float coef = 100 / (float) words;
float l = coef * letters;
float s = coef * sentences;
float index = 0.0588 * l - 0.296 * s - 15.8;
if (index > 16)
{
printf("Grade 16+\n");
}
else if (index < 1)
{
printf("Before Grade 1\n");
}
else
{
printf("Grade %.0f\n", index);
}
}