Tuesday, October 13, 2009

student with pointer

include"stdio.h"
#include"string.h"
#include"conio.h"
#include"stdlib.h"
/*9. Allocate memory for number of students, take those marks, and find average, by
* using pointer concept */
struct student
{
int mark;
};

struct student *no[10];


int main()
{
int i=0,sum=0,n,avg;
printf("enter the number of students list want to create\n");
scanf("%d",&n);
while(i{
no[i]=(struct student *)malloc(sizeof(struct student ));
printf("enter the %d student mark\n",i+1);
scanf("%d",&no[i]->mark);
i++;

}
printf("****display****");
i=0;
while(i {
printf(" the %d student mark is %d\n",i+1,no[i]->mark);
sum=sum+no[i]->mark;
i++;

}
avg=sum/n;
printf("the average value of %d student mark is:%d",n,avg);

getch();
return 0;
}

No comments:

Post a Comment