QP School

Full Version: Working with integers from user input in C
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Example:

int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("Your age is: %d\n", age);

Explanation:

In this example, we declare an int variable age to store the user's age.
We prompt the user to enter their age using printf().
We use the %d format specifier in scanf() to read an integer value from the user and store it in the age variable.
Finally, we print the user's age using printf().