Write a program which asks the user to enter the name and age of persons in his group. The number of persons is not known to the user in the beginning of the program. The user keeps on entering the data till the user enters the age as zero. The program finally prints the average age.
#include <stdio.h>
#include <conio.h>
void main ( )
{
int age, totage = 0, n = 0;
char name[40];
float avgage = 0;
clrscr ( );
do
{
fflush ( stdin );
printf("\n\n\t\t Enter name.:"); gets(name);
fflush ( stdin );
printf("\t\t Enter age..:"); scanf("%d",&age);
totage = totage + age;
n++;
} while ( age != 0 );
avgage = ( float ) totage / n;
printf("\n\n\n\n\t\t Average age=%.2f",avgage);
getch ( );
}
Click here to contact us
#include <stdio.h>
#include <conio.h>
void main ( )
{
int age, totage = 0, n = 0;
char name[40];
float avgage = 0;
clrscr ( );
do
{
fflush ( stdin );
printf("\n\n\t\t Enter name.:"); gets(name);
fflush ( stdin );
printf("\t\t Enter age..:"); scanf("%d",&age);
totage = totage + age;
n++;
} while ( age != 0 );
avgage = ( float ) totage / n;
printf("\n\n\n\n\t\t Average age=%.2f",avgage);
getch ( );
}
Click here to contact us
No comments:
Post a Comment