Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h> // vertical word length histogram program, copyright theelitenoob
- int main(int argc, char *argv[]){
- int t[10 + 1] = {0}, wordLength = 0, maxValue = 0, c, i, j; // declare variables
- while((c = getchar()) != '\n') // get input
- (c != ' ' && c != '\t' && c != '\r') ? ++wordLength : ((wordLength > 10) ? ++t[10] : ++t[wordLength - 1], wordLength = 0);
- for(i = 0; i != 10 + 1; ++i) // set up array
- if(t[i] > maxValue) maxValue = t[i];
- for(i = maxValue; i != 0; --i, putchar('\n')){ // put the new lines you need
- for(j = 0; j != 10 + 1; ++j){ // print out the x for the row
- (t[j] >= i) ? printf(" X ") : printf(" ");
- putchar(' '); // blank space
- }
- }
- for(i = 0; i != (10 + 1)*4 - 1; ++i, putchar('-')); // row separator
- for(putchar('\n'), i = 0; i != 10 + 1; ++i)
- (i != 10) ? printf("%03d ", i + 1) : printf(">%02d", 10); // print out the numbers for word lengths
- return 0; // end program
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement