C/C++の宿題を片付けます 68代目
■ このスレッドは過去ログ倉庫に格納されています
0054デフォルトの名無しさん
2006/06/25(日) 23:47:22構造体使う意味が分からんのだが、こういうこと?
#include <stdio.h>
#define MONTH 12
typedef struct {
double temperature ;
int precipitation ;
}Weather ;
double temperature[] = {3.6,4.3,7.5,13.5,18.0,21.7,25.6,26.8,22.8,16.9,11.4,6.2} ;
int precipitation[] = {50,61,98,153,162,210,218,170,209,121,74,48} ;
int main(void) {
Weather data[MONTH] ;
int i ;
double tmp,pre ;
tmp=pre=0 ;
for(i=0;i<MONTH;i++) {
data[i].temperature = temperature[i] ;
data[i].precipitation = precipitation[i] ;
}
for(i=0;i<MONTH;i++) {
tmp += data[i].temperature ;
pre += data[i].precipitation ;
}
printf("temperature avg:%lf,precipitation avg:%lf\n",tmp/MONTH,pre/MONTH) ;
return(0) ;
}
それとも問題文の理解ミス?
■ このスレッドは過去ログ倉庫に格納されています