Monday, 14 March 2016

C Program to Print a Integer Entered by a User



C Program to Print a Integer Entered by a User


Source Code

#include <stdio.h>
int main()
{
    int num;
    printf("Enter a integer: "); 
    scanf("%d",&num);  /* Storing a integer entered by user in variable num */
    printf("You entered: %d",num);
    return 0;
}


Output
Enter a integer: 25
You entered: 25


In this program, a variable num is declared of type integer using keyword int. The printf() function prints the content inside quotation mark which is "Enter a integer: ". Then, the scanf() takes integer value from user and stores it in variable num. Finally, the value entered by user is displayed in the screen using printf().

No comments:

Post a Comment