Hackerrank Solution - Hello world:
Welcome back Guys!!
In this post we will solve Hello world Hackerrank problem
It is an indtroductory problem in C language....
Problem Statement For the Hello World Hackerrank problem:
Objective
In this challenge, we will learn some basic concepts of C that will get you started with the language. You will need to use the same syntax to read input and write output in many C challenges.
Task
This challenge requires you to print on a single line, and then print the already provided input string to stdout.
Note: You do not need to read any input in this challenge.
Input Format
You do not need to read any input in this challenge.
Output Format
Print on the first line, and the string from the given input on the second line.
Sample Input 0
Welcome to C programming.
Sample Output 0
Hello, World!
Welcome to C programming.
Solution code For the Hello World Hackerrank problem:
Problem with scanf is that as soon as it encounters space while reading a string it
stops taking input so we either use scanf("%[^\n]%*c", &s) or can use gets function;
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
char s[100];
scanf("%[^\n]%*c", &s);
// gets(s) another alternative to read string
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
printf ("Hello, World! \n" "%s",s);
return 0;
}
Hope this added some knowledge and helped you.
Feel free to share your thoughts and doubts in the comment section below
Check out my youtube video as well.
See you next time.
0 Comments