Solution for Exercise 9-4
ex0904
#include <stdio.h> int main() { int count; for(count=11; count<=19; count=count+1) { printf("%d\t",count); } putchar('\n'); return(0); }
Notes
* The first task was to have the loop display values 11 through 19. The value of count
is initialized to 11 in Line 7.
* The ending value of 19 is also specified at Line 7, in the for statement. The<=
operator is used, so the value 19 can be specified directly. Otherwise, if <
was used, the comparision would have to be count<20
.
* The "repeat each" part of the loop remains the same so that values from 11 through 19 are displayed one after the other.
* In Line 9, the \t
escape sequence represents the Tab character, which separates each value displayed.
* Finally, Line 11 adds the putchar() function with the \n
newline character. That newline cleans up the output. Of course, you could also use a printf() function to display the new line, as in:
printf("\n");
* On my screen, the output looks like this:
Copyright © 1997-2024 by QPBC.
All rights reserved