You are on page 1of 2

Array Programs

Program to input the age of different persons and count the number of persons
in the age group 50 and 60.

#include <stdio.h>

intmain()
{
intage[100],i,n,count=0;
printf(“Enter the number of persons required:”);
scanf(“%d”,&n);
printf(“Enter ages of %d persons:”n);
for(i=0;i<n;i++)
{
scanf("%d",&age[i]);
if(age[i]>=50 && age[i]<=60)
count=count+1;
}
printf("Persons between 50 and 60 are: %d", count);

return0;
}
Output:
Enter number of persons required:3
Enter ages of 3 persons:
51
55
20
Persons between 50 and 60 are:2
Program to input current day and month from user.
Calculate and display the total number of daysin the
current year till the entered date.

#include <stdio.h>

intmain()
{
intday,month,total=0;
int days_per_month[12]={31,28,31,30,31,30,31,31,30,31};
printf(“Enter the month number”);
scanf(“%d”,&month);
printf(“Enter day number”);
scanf(“%d”,&day);
for(int i=0;i<month;i++)
total+=days_per_month[i];
printf("number of days in the year till date are:%d",total);

return0;
}
Output:

Enter the month number: 6

Enter day number: 6

Number of days in the year till date are:157

You might also like