Day 0 Hello World in C Hackerrank Solution, 30 Days of Code in just a single click. We are going to solve the day 0 to day 30 total of 30 days of programming problems day by day in C Language. This is the first programming problem of 30 days of code for a hackerrank website. Hello, the world is the first program ever written in any programming language.
So basically in this program, we have to print a string Hello, World. Here we will choose C++ Domain for coding and find all solutions of the 30 Days Challenges Series. So in C++ " cout<< " is used for printing anything in the terminal so we will put the string "Hello, World." in double quotes, Below is an explanation of the program step by step.
Submit Day 0 Hello World solution in all three languages:- Click Here
Day 0 Hello World in C Hackerrank Solution
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
/* Declare a variable named 'input_string' to hold our input.*/
char input_string[105];
/* Read a full line of input from stdin and save it to our variable, input_string.*/
scanf("%[^\n]", input_string);
/* Print a string literal saying "Hello, World." to stdout using printf.*/
printf("Hello, World.\n");
/* TO DO: Write a line of code here that prints the contents of input_string to stdout.*/
/* Solution starts from here */
printf("%s", input_string);
/* Solution ends here */
return 0;
}
Explanation Hackerrank Hello World in C Solution
string input_string;
input_string is a variable which stores the string " Hello, World. " in string format. We know that we can store strings or characters also, there is no limitation. A string may contain many characters there is no limitation.
getline(cin, input_string)
getline is used to store multiple strings with included space and next-line. getline reads line by line and stores the string in the variable and cin is used for storing anything in C++.
cout << "Hello, World." << endl;
as I already mention that cout is stream output and printf(" ") in C is a function. So for printing any string and number we just put the string between double quotes.
0 Comments: