Print characters that have a special meaning in printf.
What to build
Four lines that need escape sequences. The line that reads the number is written for you.
Requirements
- Line 1:
n = N - Line 2:
"n" is N, with the double quotes. - Line 3:
N% of 100 is N, with a percent sign. - Line 4:
path: C:\N, with a backslash.
Input
One whole number.
Output
Four lines.
Constraints
The number is from 0 to 100.
Example
Input:
5
Output:
n = 5
"n" is 5
5% of 100 is 5
path: C:\5
Why it works
Quotes end a string, a backslash starts an escape and a percent sign starts a format code, so each of them needs its own way of being printed literally.
Examples
Example 1 · Input
5
Expected output
n = 5 "n" is 5 5% of 100 is 5 path: C:\5
Example 2 · Input
0
Expected output
n = 0 "n" is 0 0% of 100 is 0 path: C:\0
Hints
Hint 1
Inside a string, \" prints a double quote, and \\ prints a backslash.
Hint 2
%% prints one percent sign.
Hint 3
Each line uses the value n in a different place.
Solution
Show one correct solution (try it yourself first)
#include <stdio.h>
int main(void) {
int n;
scanf("%d", &n);
printf("n = %d\n", n);
printf("\"n\" is %d\n", n);
printf("%d%% of 100 is %d\n", n, n);
printf("path: C:\\%d\n", n);
return 0;
}