C Program to take input from users and print

In this article, we are going to learn how to take input from the user and print it. Here we will learn, How to take integer input from users in the C program. How to take character input from users in the C program and the concepts to do these in C language.

Also, we will learn how to print integers entered by the user in the C program and how to print character input entered by the user in the C program.

C Program to take input from user and print


#include <stdio.h>

int main() {   
    int numInput;
    char charInput;
    
    printf("\n\nPlease enter an Character: ");
    // User Input the Character
    scanf("%c", &charInput);
  
    // Output the Character on Console
    printf("\nThanks for entering Character: %c", charInput);
   
    printf("\n\nPlease enter an integer: ");  
    // User Input the integer
    scanf("%d", &numInput);

    // Output the integer on Console
    printf("\nThanks for entering Number: %d", numInput);


    return 0;
}

Output

Please enter an Character: a

Thanks for entering Character: a

Please enter an integer: 12

Thanks for entering Number: 12

Explanation of Code:


Here we are making use of the scanf() function to take the user inputs. By using %d for integer and %c for a character we are specifying the format of the input that we are expecting from the user.