Match the symbol you would see in a printf function call to its meaning
%d
int
\n
newline character
%g
float
\t
tab character
%s
string
%c
char
Exercise1.2.2.Debug I/O statements.
What is wrong with the following code? It’s supposed to ask the user to input their age and then read from the keyboard into the variable named age.
int age;
printf("Enter your age: ");
scanf("%d", age);
There is a missing & in front of age.
Correct! The second parameter to scanf is an address (pointer).
The %d should be %g
Incorrect. The type of age is int.
The %d should be %c
Incorrect. The type of age is int.
The printf should be scanf
Incorrect.
The scanf should be printf
Incorrect.
The scanf should be printf and the printf should be scanf
Incorrect.
Exercise1.2.3.Parsons Problem: A Program with I/O.
Write a program that prompts the user to input the base and height of a right triangle (both of these should be floats) and then outputs the area of the triangle.
#include <stdio.h>
int main(void) {
---
float base, height, area;
---
printf("Please enter the base and height of a right triangle: ");
---
scanf("%g%g", &base, &height);
---
area = 0.5 * (base * height);
---
printf("The area of the right triangle is: %g\n", area);
---
return 0;
}
---
scanf("%g%g", base, height); #distractor
---
printf("The area of the right triangle is: %d\n", area); #distractor
---
area = base * height; #distractor
---
printf(“%g%g, base, height); #distractor