#include stdio.h
#include conio.h
#include string.h
#define max_no 20
/*defining structure */
typedef struct{
char name[15];
int age;
}person;
void main(){
person p[max_no]; // defining structure with array
int i,j,max;
printf("enter the max number of students\n");
scanf("%d",&max);
for( i=0;i<max;i++)
{
printf("\n enter name : ");
scanf("%s",&p[i].name);
printf("\n enter age for %s : ",p[i].name);
scanf("%d",&p[i].age);
}//end of for loop
printf("\n Name \t age \n");
printf("-----------\n");
for(j=0;j<max;j++)
{
printf(" %s \t %d \n",p[j].name,p[j].age);
printf("-----------\n");
}//end of for loop
getch(); // used to hold the display
}//end of main
Output
No comments:
Post a Comment