/* * This program demonstrates output features in C. * Author: David Janzen */ #include int triple(int num) { return num * 3; } int main(void) { char ch; int num; double realNum; /* Simple output */ printf("This gets printed to the screen"); printf("This also is printed, but with a new line at the end\n"); /* Output with placeholders: %c for char, %d for int, %f for double */ printf("4 * 2 is: %d\n", 4 * 2); printf("Let's print results of two expressions: %d, %d\n", 5 + 2, 6 * (4 - 1)); num = (7 + 3) / 2; printf("num has the value: %d\n", num); printf("triple(5) is: %d\n", triple(5)); printf("You get an %c\n", 'A'); ch = 'M'; printf("My favorite candy is %c & %c's\n",ch,ch); printf("Check out this double: %f\n", 3.750); realNum = 14.943; printf("Check out this double: %f\n", realNum); /* Formatting output */ printf("Now format it with %%1f: %1f\n", realNum); printf("Now format it with %%1.1f: %1.1f\n", realNum); printf("Now format it with %%5.2f: %5.2f\n", realNum); printf("Now format it with %%5.4f: %5.4f\n", realNum); printf("Now format it with %%9.4f: %9.4f\n", realNum); printf("Format a char with %%c: %c\n", ch); printf("Format a char with %%4c: %4c\n", ch); printf("Format an int with %%d: %d\n", num); printf("Format an int with %%4d: %4d\n", num); printf("Give an int a char: %d\n", ch); printf("Give a char an int: %c\n", num); return 0; }