/*広告*/

/*[C言語]サンプルプログラム集 合計ソース3*/

/*目次へ戻る*/

#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> struct STUDENT{ char name[128]; int money; }; struct STUDENT set_data(const char* , int); int my_sum2(struct STUDENT* ,int); int main(){ struct STUDENT student[5]; int sum = 0; int i; student[0] = set_data("tanaka",1000); student[1] = set_data("suzuki",2000); student[2] = set_data("satou",3000); student[3] = set_data("saitou",4000); student[4] = set_data("watanabe",5000); sum = my_sum2(student,sizeof(student) / sizeof(struct STUDENT)); for(i=0;i<5;i++){ printf("name:%s money:%d\n",student[i].name,student[i].money); } printf("sum = %d\n",sum); return 0; } struct STUDENT set_data(const char* name, int money){ struct STUDENT tmp; strcpy(tmp.name,name); tmp.money = money; return tmp; } int my_sum2(struct STUDENT* ary,int size){ int sum = 0; int i; for(i=0;i<size;i++){ sum += (ary + i)->money; } return sum; }

/*ページの先頭へ*/

/*目次へ戻る*/

/*HOME*/

/*Copyright 2016 K.N/petitetech.com*/

/*広告*/