Playing With Characters - Hacker Rank Solution

Playing With Characters
Playing With Characters - Hacker Rank Solution



Problem :

 

Problem Statement Link :-

 


Sample Input 0

C
Language
Welcome To C!!

Sample Output 0

C
Language
Welcome To C!!



Solution :-


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Playing With Characters - Hacker Rank Solution
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MAX_LIMIT 40
int main() 
{

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    // Playing With Characters - Hacker Rank Solution START  
    char ch;
    char s[MAX_LIMIT];
    char sen[MAX_LIMIT];
    scanf("%c",&ch);
    scanf("%s",&s);
    scanf("\n");
    scanf("%[^\n]%*c", sen);
    printf("%c\n%s\n%s",ch,s,sen); 
    // Playing With Characters - Hacker Rank Solution END
    return 0;
}




Next Post Previous Post
3 Comments
  • ANONYMOUS
    ANONYMOUS Friday, July 02, 2021

    just one question
    why do we take next line character as input here???
    scanf("%c",&ch);
    scanf("%s",&s);
    scanf("\n");
    scanf("%[^\n]%*c", sen);
    last 2nd line !!

  • Anonymous
    Anonymous Saturday, August 14, 2021

    The statement: scanf("%[^\n]%*c", s); will not work because the last statement will read a newline character, so use scanf("\n"); before the last statement.

  • sumith
    sumith Saturday, April 16, 2022

    #include
    #include
    #include
    #include

    int main() {

    char s[100];
    gets(s);
    for(int i=0;i<strlen(s);i++)
    {
    if(s[i]==' ')
    {
    printf("\n");
    }
    else
    {
    printf("%c",s[i]);
    }
    }

    return 0;
    }

Add Comment
comment url