Write a C program to read age of 100 students and display youngest and eldest age.
Here's a C program that prompts the user to enter the age of 100 students and then displays the youngest and eldest age:
#include <stdio.h>
int main()
{
int i, age, youngest_age=100, eldest_age=0;
for(i=0; i<100; i++)
{
printf("Enter the age of student %d: ", i+1);
scanf("%d", &age);
if(age < youngest_age)
{
youngest_age = age;
}
if(age > eldest_age)
{
eldest_age = age;
}
}
printf("The youngest age is: %d\n", youngest_age);
printf("The eldest age is: %d\n", eldest_age);
return 0;
}
Comments
Post a Comment