-->

program to read age of any 100 persons and count the number of persons in the age group between 20 and 40.

/*program to read age of any 100 persons and count the number of persons in the age group between 20 and 40.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int total_person,person_age,count=0,k;
printf("enter total number of persons\n");
scanf("%d",&total_person);
for(k=1;k<=total_person;k++)
   {
        printf("enter age of persons\n");
         scanf("%d",&person_age);
           if(person_age>=20 && person_age<=40)
               {
                 count=count+1;
               }
    }
printf("total persons falling in range=%d",count);
getch();
}
--------------------------------------------------------------------------------------------------------------------------------------------------
logics in mind:-
->we need person's age,total persons,and count variable
->enter total number of persons o you can take 100 as  fixed value
->use loop to enter age repeatedly 100 times.
               ->input age inside loop
->we have to count ages so we use 'if' inside loop as shown above.
->inside loop, if the condition matches then 'count' goes for increment.
->this testing goes for 100 times
->then it stops
->last value of 'count' is then displayed.

note:
better to use array for above program.

No comments:

Post a Comment