Print a greeting for the name that was typed.
What to build
Two lines of output. The line that reads the input is already written for you, and the lesson on input explains it.
Requirements
- Print
Hello, NAME!on the first line. - Print
Welcome to C.on the second line.
Input
One word: a name.
Output
Two lines.
Constraints
The name has from 1 to 49 letters.
Example
Input:
Rahim
Output:
Hello, Rahim!
Welcome to C.
Why it works
%s is the format code for text, so printf places the name exactly where the marker stands.
Examples
Example 1 · Input
Rahim
Expected output
Hello, Rahim! Welcome to C.
Example 2 · Input
Nadia
Expected output
Hello, Nadia! Welcome to C.
Hints
Hint 1
The line that reads the name is written for you. Use %s to print a string.
Hint 2
Remember the \n at the end of each line.
Solution
Show one correct solution (try it yourself first)
#include <stdio.h>
int main(void) {
char name[50];
scanf("%49s", name);
printf("Hello, %s!\n", name);
printf("Welcome to C.\n");
return 0;
}