c语言求助.
int x,y;scanf("%d %d",&x,&y);
int hour1=x/100;
int minute1=x%100;
int hour2=y/100;
int minute2=y%100;
int z=(hour1*60+minute1)-(hour2*60+minute2);
int hour3=z/60;
int minute3=z%60;
int t=hour3*100+minute3;
printf("%d\n",t);
return 0;
要求输入1120(11小时20分)110(1小时10分)
输出1310
我一直输出的1010,完全懵了{:10_269:} int z=(hour1*60+minute1)-(hour2*60+minute2);这句,660+20-(60+10)=660+20-60-10=610,所以输出1010 你所给答案也是错误的!11点20分 + 1点10分 = 12点30分
#include <stdio.h>
int main()
{
int x, y;
scanf("%d%d", &x, &y);
int hour1 = x / 100;
int minute1 = x % 100;
int hour2 = y / 100;
int minute2 = y % 100;
int z = (hour1 * 60 + minute1) + (hour2 * 60 + minute2);// 应是加法!此处用减法,还能不得1010?
int hour3 = z / 60;
int minute3 = z % 60;
int t = hour3 * 100 + minute3;
printf("%d\n", t);
return 0;
}
页:
[1]