Reading data from Keyboard in C Language

Views: 136   

You can use the builtin scanf function to read data from keyboard.
Following is a sample C Language program, which reads your age and prints whether you are Infant or Child or Adult based on the Input given.

#include <stdio.h>

int main() {
    int age;
    printf("Enter the age:");
    scanf("%d", &age);

    if (age >= 0 && age <= 5) {
        printf("Infant");
    } else if (age >= 6 && age <= 17) {
        printf("Child");
    } else if (age >= 18) {
        printf("Adult");
    } else {
        printf("Invalid input");
    }
}

Output:

Enter the age:23
Adult
On By