/*広告*/

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

/*目次へ戻る*/

#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> struct STUDENT{ char name[128]; int score; }; struct STUDENT set_data(const char* , int); int my_max2(struct STUDENT* ,int); int main(){ struct STUDENT student[5]; int max = 0; int i; student[0] = set_data("tanaka",385); student[1] = set_data("suzuki",212); student[2] = set_data("satou",445); student[3] = set_data("saitou",500); student[4] = set_data("watanabe",293); max = my_max2(student,sizeof(student) / sizeof(struct STUDENT)); for(i=0;i<5;i++){ printf("name:%s score:%d\n",student[i].name,student[i].score); } printf("max = %d\n",max); return 0; } struct STUDENT set_data(const char* name, int score){ struct STUDENT tmp; strcpy(tmp.name,name); tmp.score = score; return tmp; } int my_max2(struct STUDENT* ary,int size){ int max = 0; int i; max = ary->score; for(i=1;i<size;i++){ if(max < (ary + i)->score){ max = (ary + i)->score; } } return max; }

/*ページの先頭へ*/

/*目次へ戻る*/

/*HOME*/

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

/*広告*/