Home » Blog » Take Input From User Of Different Datatypes In C

Take Input From User Of Different Datatypes In C

Here, printf() is used to display text on the screen.

The sign & is used to assign the input value to the variable and store it at that particular location. scanf() is used to take input from the user using format specifier. %d and %i, both are used to take integer numbers as input from the user. %f is the format specifier to take float as input from the user. %c is the format specifier to take character as input from the user. %s is the format specifier to take string as input from the user but %s cannot get string with white space from user, it means it can get only one word.

#include<stdio.h>
#include<conio.h>

void main()
{
    int num1, num2;  
    float f;     
    char c;

    clrscr();
	
    printf("Enter two numbers number\n");
    
    // Taking integer numbers as input from user
    scanf("%d%i", &num1, &num2);
    printf("\nThe two numbers You have entered are %d and %i\n\n", num1, num2);

    printf("\n\nEnter a Decimal number\n");
	
    // Taking float or fraction number as input from the user
    scanf("%f", &f); 
    printf("\n\nThe float or fraction number that you have entered is %f", f);

    // Taking c as input from the user
    printf("\n\nEnter a character\n");
    scanf("%c",&c);
    printf("\n\nThe character that you have entered is %c", c);
    
    getch();
}

OutPut

Enter two numbers number

31 12

The two numbers You have entered are 31 and 12


Enter a Decimal number

22.8
	
The float or fraction number that you have entered is 22.8


Enter a character

s

The character that you have entered is s

It’s  Done Keep It Up Guys…

Leave a Reply

Your email address will not be published.