What you learn from the problem

  • This solution will help you To learn how to take character ,string and a sentence as the input in c ,In the hacker rank platform.


Playing with characters



Explanation

        About-Problem

  • One thing i want to tell all of you that Hacker Rank does not support The (gets() function to take  input string after the space so i will tell you the another method ).

  •   scanf("%[^\n]%*c", s);

  • so we have to do this method to take multiple strings after the space ,and this method is already mention in the Hacker Rank.

  • Like this for taking character input and print we use.
  • char ch;
    scanf("%c", &ch);
    printf("%c", ch);

Input-format

First, take a character, ch as input.
Then take the string, s as input.
Lastly, take the sentence sen as input.

Output Format

Print three lines of output. The first line prints the character, .
The second line prints the string, .
The third line prints the sentence, .


Code


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() 
{
   //Read input from STDIN.

// Print output to STDOUT   
    char ch,s[50],sen[100];
    scanf("%c", &ch);  
    scanf("%s\n",s);
    scanf("%[^\n]%*c",sen);
    
    printf("%c\n",ch);
    printf("%s\n",s);
    printf("%s",sen);
    return 0;

}



Explanation

    About solution

  • First of all add all your required Header files for this problem and next for string input we have to include (string .h) header file .And then declare char ch, and array of [50] ,sen [100] .

  • Then we use The  scanf function for taking the inputs and use \n for taking new lines because we need to take inputs in new line so we use here \n.

  • And then use printf function to print the outputs for character we use %c(format spacefire),%s for string output  and here also we use \n for new line in the output

  • That is it for this article still if you have any doubt regarding this please comment below and share it with your friends . and suggest us some improvement on our articles. Thank you.

Also check Out





  Q-2)  pointers in c




  

   Q-3) Vector Sort


Also check Out Projects for Resume

    click here

Projects on C++


Projects on C


Problems On C


Problems On C++


Feedback!!

  • If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!

  • Once again Thank you for Reading this !!!😀😀


     >> Happy Coding!!

     >> Ramji!!!