C言語の問題で難しすぎて困っています。どうか助けて下さい。
Posted: 2014年7月19日(土) 14:39
C言語の問題で難しすぎて困っています。どうか助けて下さい。
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
以下のプログラムについて,外部仕様および内部仕様をまとめよ.
#include <stdio.h>
#include <math.h>
/* 座標を表す構造体 */
typedef struct {
int x; /* x座標 */
int y; /* y座標 */
} position;
typedef struct {
position pos; /* 座標を表す構造体(x 座標と y座標をもつ) */
double fuel; /* 残りの燃料量 */
} car;
int move(car *c, int dx, int dy)
{
double dist; /* 移動距離 */
dist = sqrt(dx*dx+dy*dy); /* 移動距離(=消費燃料)の計算 */
if(dist > c->fuel) /* 移動距離と残燃料量の比較 */
{
return 1; /* 燃料が不足していたら1を返す */
}
else
{
c->pos.x += dx; /* x 座標を更新 */
c->pos.y += dy; /* y 座標を更新 */
c->fuel -= dist; /* 残燃料量を更新 */
return 0; /* 燃料が足りていたら0を返す */
}
}
int main(void)
{
car c={{2,3},10.0}; /* 構造体の初期化 座標(2,3) 残燃料量 10.0 */
int dx, dy;
printf("x方向に進む距離:"); /* x方向の移動(整数)の入力 */
scanf("%d",&dx);
printf("y方向に進む距離:"); /* y方向の移動(整数)の入力 */
scanf("%d",&dy);
/* 移動距離を計算し残燃料量と比較し,移動する関数を呼び出し */
if(!move(&c,dx,dy))
{
printf("残燃料量:%f¥n",c.fuel); /* 残燃料量の表示 */
printf("到達地点の座標は:(%d, %d)¥n",c.pos.x,c.pos.y); /* 移動後の座標の表示 */
}
else
{
printf("燃料が足りません!¥n"); /* 「燃料不足」を表示 */
}
return 0;
} /*以上*/
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
どうか力を貸してください。
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
以下のプログラムについて,外部仕様および内部仕様をまとめよ.
#include <stdio.h>
#include <math.h>
/* 座標を表す構造体 */
typedef struct {
int x; /* x座標 */
int y; /* y座標 */
} position;
typedef struct {
position pos; /* 座標を表す構造体(x 座標と y座標をもつ) */
double fuel; /* 残りの燃料量 */
} car;
int move(car *c, int dx, int dy)
{
double dist; /* 移動距離 */
dist = sqrt(dx*dx+dy*dy); /* 移動距離(=消費燃料)の計算 */
if(dist > c->fuel) /* 移動距離と残燃料量の比較 */
{
return 1; /* 燃料が不足していたら1を返す */
}
else
{
c->pos.x += dx; /* x 座標を更新 */
c->pos.y += dy; /* y 座標を更新 */
c->fuel -= dist; /* 残燃料量を更新 */
return 0; /* 燃料が足りていたら0を返す */
}
}
int main(void)
{
car c={{2,3},10.0}; /* 構造体の初期化 座標(2,3) 残燃料量 10.0 */
int dx, dy;
printf("x方向に進む距離:"); /* x方向の移動(整数)の入力 */
scanf("%d",&dx);
printf("y方向に進む距離:"); /* y方向の移動(整数)の入力 */
scanf("%d",&dy);
/* 移動距離を計算し残燃料量と比較し,移動する関数を呼び出し */
if(!move(&c,dx,dy))
{
printf("残燃料量:%f¥n",c.fuel); /* 残燃料量の表示 */
printf("到達地点の座標は:(%d, %d)¥n",c.pos.x,c.pos.y); /* 移動後の座標の表示 */
}
else
{
printf("燃料が足りません!¥n"); /* 「燃料不足」を表示 */
}
return 0;
} /*以上*/
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
どうか力を貸してください。