#include <stdio.h>
int main() {
char ch;
char s[100];
char sen[100];
scanf("%c", &ch); // Read a character
scanf("%s", s); // Read a string
scanf("\n"); // Consume the newline character
scanf("%[^\n]%*c", sen); // Read a sentence
printf("%c\n", ch); // Print the character
printf("%s\n", s); // Print the string
printf("%s\n", sen); // Print the sentence
return 0;
}
Let's go through the solution step by step:
We include the
In the main() function, we declare three character arrays: ch to store a single character, s to store a string, and sen to store a sentence.
We use the scanf() function to read input from the user:
scanf("%c", &ch) reads a character and stores it in the variable ch.
scanf("%s", s) reads a string and stores it in the character array s.
scanf("\n") is used to consume the newline character after reading the string.
scanf("%[^\n]%*c", sen) reads a sentence until it encounters a newline character (\n) and stores it in the character array sen. The %[^\n] format specifier tells scanf() to read characters until it encounters a newline character. The %*c is used to consume the newline character.
Finally, we use the printf() function to print the stored values:
printf("%c\n", ch) prints the character ch.
printf("%s\n", s) prints the string s.
printf("%s\n", sen) prints the sentence sen.
By providing the expected input and executing the code, you should see the desired output according to the problem statement on HackerRank.
Please note that this solution assumes the input strings are within the specified limits (100 characters) and does not perform any error handling for simplicity.