Header Ad

HackerRank Hello World! in C programming solution

In this HackerRank Hello World! in C problem solution c programming, 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 Hello World! 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.

HackerRank Hello World! in C programming solution


HackerRank Hello World! in C Programming 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;
}


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;
}


Here in the above code, we define an array of character type and then we take input using scanf() function and store in the array. and then we print the Hello World message on the output screen using the printf() function and also print the value of array s.

Post a Comment

0 Comments