C program to input and output a number and a character

Input and Output a number and a character:-

Today we will practice some of the c programming examples which will be very simple and easy to execute.

1. The first program, in this we are taking a character input from user and print that character on the screen. Refer the program below for understanding better.
#include <stdio.h>
int main()
{
char ch;
printf("Enter a character to be display: ");
scanf("%c", &ch);
printf("The character entered is: %c", ch);
return 0;
}
Output : Enter a character to be display: A The character entered is: A
2. The second program is similar to the first program where we take a character as input and prints it on the screen where as in this program we take the input as an integer and similarly prints that on the screen.
#include <stdio.h>
int main()
{
int num;
printf("Enter a number to be display: ");
scanf("%d", &num);
printf("The number entered is: %d", num);
return 0;
}
output:- Enter a number to be display: 12 The number entered is: 12

3. This program is also similar to the to the programs one and two where we take the input and print on the screen. Here we are taking a float value and printing it.
#include <stdio.h>
int main()
{
float value;
printf("Enter value: ");
scanf("%f", &value);
printf("The value entered is: %f", value);
return 0;
}
output:- Enter value: 25 The value entered is: 25.000000

4.The below program takes two inputs one is a character and other one is an integer value
First we input a character and then an integer in the below diagram. 
#include <stdio.h>
int main()
{
char ch;
int n;
printf("Enter a character") ;
scanf("%c", &ch) ;
printf("Enter an Integer value") ;
scanf("%d", &n) ;
printf("The entered character is %c and the entered integer is %d, ch, n) ;
return 0;
}
Output: Enter a character A Enter an Integer value 2 The entered character is A and the entered integer is 2

Post a Comment

0 Comments