Write a program to input a single character and display it.

#include<stdio.h>
#include<conio.h>
int main()
{
	char ch;
	printf("Enter any character:");
	scanf("%c",&ch);
	printf("\n Your entered character is: %c",ch);
	getch();
}

The program allows the user to enter a character and display it using the printf statement.

The program starts with the inclusion of the standard input-output library, stdio.h, and console input-output library, conio.h.

The main() function is defined and it begins with the declaration of the variable ch which is a character type.

Next, the program prompts the user to input a character using the printf() function with the string argument “Enter any character:”.

Then the scanf() function is used to read a single character from the user and store it in the variable ch.

Finally, the entered character is displayed on the console using the printf() function with the string argument “Your entered character is: %c” and the variable ch is used to display the character.

The getch() function is used to hold the console window open until a key is pressed.

Thanks

Write a program to input a single character and display it.

Leave a Reply

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

Scroll to top