#include <stdio.h>
struct MESSAGE
{
int gene;
int end;
int delay;
};
void delay(struct MESSAGE data[], int i);
void average(struct MESSAGE data[], double *ave);
int main(void)
{
struct MESSAGE data[10]; int i;
double ave;
//<メッセージの発生時刻と到着時刻の値の代入>
data[0].gene = 0;
data[0].end = 25;
data[1].gene = 5;
data[1].end = 30;
data[2].gene = 10;
data[2].end = 38;
data[3].gene = 15;
data[3].end = 50;
data[4].gene = 20;
data[4].end = 52;
data[5].gene = 25;
data[5].end = 55;
data[6].gene = 30;
data[6].end = 57;
data[7].gene = 35;
data[7].end = 60;
data[8].gene = 40;
data[8].end = 65;
data[9].gene = 45;
data[9].end = 70;
for (i=0; i<=9; i++)
{
delay(data, i);
printf("メッセージ%dの転送時間は%dミリ秒 \n",i
, data
[i
].
delay); }
average(data, &ave);
printf("平均メッセージ転送時間は%fミリ秒 \n", ave
); return 0;
}
void delay(struct MESSAGE data[], int i)
{
//<メッセージiの転送時間の計算>
data[i].delay = data[i].end - data[i].gene;
}
void average(struct MESSAGE data[], double *ave)
{
int i, total = 0;
//<平均メッセージ転送時間の計算>
for (i=0; i<=9; i++)
{
total += data[i].delay;
}
*ave = total / 10.0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CnN0cnVjdCBNRVNTQUdFCnsKIGludCBnZW5lOwogaW50IGVuZDsKIGludCBkZWxheTsKfTsKCnZvaWQgZGVsYXkoc3RydWN0IE1FU1NBR0UgZGF0YVtdLCBpbnQgaSk7CnZvaWQgYXZlcmFnZShzdHJ1Y3QgTUVTU0FHRSBkYXRhW10sIGRvdWJsZSAqYXZlKTsKCmludCBtYWluKHZvaWQpCnsKIHN0cnVjdCBNRVNTQUdFIGRhdGFbMTBdOyBpbnQgaTsKIGRvdWJsZSBhdmU7Ci8vPOODoeODg+OCu+ODvOOCuOOBrueZuueUn+aZguWIu+OBqOWIsOedgOaZguWIu+OBruWApOOBruS7o+WFpT4KIGRhdGFbMF0uZ2VuZSA9IDA7CiBkYXRhWzBdLmVuZCA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