Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerRank “Hello World!” in C problem solution

YASH PAL, 10 July 20242 October 2025

In this tutorial, we are going to solve the HackerRank “Hello World” in c problem and provide a solution that you can use to solve the 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. As you work through these problems, review the code stubs to learn about reading from stdin and writing to stdout.

Task

This challenge requires you to print  on a single line, and then print the already provided input string to stdout. If you are not familiar with C, you may want to read about the printf() command.

Example

The required output is:

Hello, World!  
Life is beautiful  

Function Descriptio

Complete the main() function below.

The main() function has the following input:

  • string s: a string

Prints

  • *two strings: * “Hello, World!” on one line and the input string on the next line.

Input Format

There is one line of text, .

Sample Input 0

Welcome to C programming.

Sample Output 0

Hello, World!
Welcome to C programming.

HackerRank “Hello World!” in C solution

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() 
{
	
    char s[100];
    scanf("%[^\n]%*c", &s);
    printf("Hello, World!\n");
    printf("%s",s);
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
    return 0;
}

Explanation

Here in the above code, we have used a string of length 100 to hold the value that we are going to scan or read from the input screen and scan a value from the user input screen using the scanf() function and then we printed the value Hello, World! in first line using the printf() function. and then we used the \n code to go to next line to print another value

After that, we again used the printf() function to print the value of a variable.

Second solution

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>


int main ()
{
    char s[100];
    fgets(s, sizeof(s), stdin);
    printf("Hello, World!\n%s", s);
    
    return 0;
}

Explanation

In this solution first, we included the necessary header file stdio.h, string.h, math.h, stdlib.h, after that in the main() function we defined a character string of length 100 to hold the string value that we will read from the input screen. after that, we use the fgets() function to read the value from the user input screen.

And then we used the printf() function to print the Hello, World! string on the output screen and then \n to go to the next line and %s format specifier to print the value of string s.

C Solutions Hackerrank Problems Solutions cHackerRank

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes