|
CS256 - Fundamentals of Structured Programming
| Displaying exercises/e6/solution/p5.c
#include <stdio.h>
/**
* Print three columns of numbers followed by the ASCII character for that
* number. The first column is in the range 32 to 63 in steps of 1. The second
* columns 32 more than that and the third is 64 more than that.
* - Print each columns number right aligned to three characters followed by
* a space then the ASCII character for that number. Use tabs between
* columns and a newline at the end of the third column.
* Hints: In printf, %#d will format a decimal number to be right aligned #
* spaces and %c prints the character of the number given. Make multiple
* printfs (w/o newlines) to output one line of text, so consider one
* printf / column.
*
* Example output:
* 32 64 @ 96 `
* 33 ! 65 A 97 a
* 34 " 66 B 98 b
* 35 # 67 C 99 c
* ...
* 62 > 94 ^ 126 ~
* 63 ? 95 _ 127
*/
int main(void)
{
int c;
int lower, upper, step;
lower = 32;
upper = 63;
step = 1;
c = lower;
while (c <= upper) {
printf("%3d %c\t",c,c);
printf("%3d %c\t",c+32,c+32);
printf("%3d %c\n",c+64,c+64);
c = c + step;
}
return 0;
}
|