🧾 Program Statement
Write a C program to accept a character from the user and display it.
#include<stdio.h>
int main() {
// char ch = 'a';
// char ch = 97;
// char ch = 0141;
// char ch = 0x61;
//user defined
char ch = 0;
printf("Enter the Character 'a'\n");
scanf("%c",&ch);
printf("Your Character is:- %c\n", ch);
}
🔍 Line-by-Line Explanation
#include<stdio.h>
This line includes the Standard Input Output header file.
It allows us to use functions like printf() and scanf().
int main()
This is the main function where program execution starts.
char ch = 0;
Here, we declare a variable named ch of type char.
It is used to store a single character entered by the user.
printf("Enter the Character 'a'\n");
This line prints a message asking the user to enter a character.
The \n moves the cursor to the next line.
scanf("%c",&ch);
This line reads a character from the keyboard.
%cis the format specifier for character.&chstores the entered character into the variablech.
printf("Your Character is:- %c\n", ch);
This statement prints the character stored in ch.
return 0;
This indicates successful termination of the program.
#output
Enter the Character 'a'
a
Your Character is:- a
Note :- while scanning the data from the user using scnaf() function we need to take care two points
- Proper format specifier
- Proper address location
*********************************Happy Coding ************************************
#srikanthbytech
#sribeets


0 కామెంట్లు