C program to Print Integer, Char, and Float value

How to write a C program to Print Integer, Char, and Float value with an example. It will showcase the use of format specifiers in C programming.

As we all know, a scanf() statement reads user-given input from the console and stores it in a variable. The printf() statement displays the stored integer on the console.

  • %d format specifier prints the integer as the output.
  • Use the %c specifier to print a character.
  • Use the %f specifier to print a floating-point number.

C program to Print Integer, Char, and Float value

This C program lets the user enter One integer value, character, and a float value. And then we use the printf statement to print them out.

/* C program to Print Integer, Char, and Float value */

#include <stdio.h>
int main()
{
  int Integer;
  char Character;
  float InputFloat;
 
  printf(" Please Enter a Character :  ");
  scanf("%c", &Character);
  
  printf(" Please Enter an Integer Value :  ");
  scanf("%d", &Integer);
  
  printf(" Please Enter Float Value :  ");
  scanf("%f", &InputFloat);    
  
  printf(" \n The Integer Value that you Entered is :  %d", Integer);
  printf(" \n The Character that you Entered is :  %c", Character);
  printf(" \n The Float Value that you Entered is :  %f", InputFloat);
  printf(" \n The Float Value with precision 2 is :  %.2f", InputFloat);

  return 0;
}
C program to Print Integer, Char, and Float value 1

Within this program to Print Integer, Char, and Float value example; first, we declared three variable of type Integer, Character, and Float. Below statements will ask the user to enter one character, an integer value, and a floating-point value.

  printf(" Please Enter a Character :  ");
  scanf("%c", &Character);
  
  printf(" Please Enter an Integer Value :  ");
  scanf("%d", &Integer);
  
  printf(" Please Enter Float Value :  ");
  scanf("%f", &InputFloat);

Or, you can simply write the below statement instead of the above C program statement.

  printf(" Please Enter a Character, Integer, and Float Value :  ");
  scanf("%c %d %f", &Character, &Integer, &InputFloat);

Lastly, we use the C Programming printf statement to print those user entered values as output.

Also Read

Comments are closed.