총점을 부함수에서 계산하게 했음...
간접연산자를 썼다는 것과, 부함수에 구조체배열을 넘겼다는 것이 관건!
#include <stdio.h>
struct sung{
long int num;
char *name;
int jum[3];
int sum;
float ave;
};
void func(struct sung *x);
void main()
{
struct sung pp[3]={{95001,"hong",80,80,80 },
{95002,"jun",90,90,90 },
{95003,"kim",100,100,150 }};
int a,b;
/* for(a=0;a<3;a++){
for(b=0;b<3;b++)
pp[a].sum+=pp[a].jum[b];
pp[a].ave=pp[a].sum/3.0;}*/
func(pp);
printf("n");
for(a=0;a<3;a++){
printf(" printf(" for(b=0;b<3;b++)
printf(" printf(" printf("}
}
void func(struct sung *x)
{
int i,j;
for(i=0;i<3;i++){
for(j=0;j<3;j++)
(x+i)->sum+=(x+i)->jum[j];
(x+i)->ave=(x+i)->sum/3.0;}
}
간접연산자를 썼다는 것과, 부함수에 구조체배열을 넘겼다는 것이 관건!
#include <stdio.h>
struct sung{
long int num;
char *name;
int jum[3];
int sum;
float ave;
};
void func(struct sung *x);
void main()
{
struct sung pp[3]={{95001,"hong",80,80,80 },
{95002,"jun",90,90,90 },
{95003,"kim",100,100,150 }};
int a,b;
/* for(a=0;a<3;a++){
for(b=0;b<3;b++)
pp[a].sum+=pp[a].jum[b];
pp[a].ave=pp[a].sum/3.0;}*/
func(pp);
printf("n");
for(a=0;a<3;a++){
printf(" printf(" for(b=0;b<3;b++)
printf(" printf(" printf("}
}
void func(struct sung *x)
{
int i,j;
for(i=0;i<3;i++){
for(j=0;j<3;j++)
(x+i)->sum+=(x+i)->jum[j];
(x+i)->ave=(x+i)->sum/3.0;}
}
댓글 달기