Skip to content
Programming101
Programmingoneonone
  • 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
Programming101
Programmingoneonone
HackerRank playing with characters problem solution in c programming

HackerRank Playing With Characters solution in C

YASH PAL, 12 July 202413 June 2025

In this tutorial, we will solve HackerRank Playing with characters problem in c or write a solution for this problem. In this problem, we need to take a character as input, a string as input and then we need to take a sentence as an input.

The string and sentence will always be less than 100 characters. on the output screen, we need to print the three lines. first, we need to print the character value then in the second line we need to print the string value, and in the last sentence value.

Using this problem we will learn or understand how we can take a character, string, and even a full sentence as input in the c programming language.

Playing with characters problem solution
hackerrank playing with characters problem solution in c programming
Playing with characters problem

HackerRank Playing with characters Solution in C programming.

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

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

Explanation

In the above solution first, we included the necessary header files. after that we defined main() function. in the main function first we defined a character variable ch, an array of characters of length 100, and then again an array of characters with a length of 122.

After that, we use the scanf() function to read all the variable values using the %C for character variable and %s for string and sentence variable. after that, we used the printf() function to print all the values. for the new line, we have used the \n (newline character) to go to the new line.

Second solution

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

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

Explanation

This second solution is the same as the first solution. the difference is that we have used the three different scanf() functions to scan the values.

Next problem solution – HackerRank Sum and Difference of Two Numbers solution in c

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

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes