回复 5楼 Tomorrw_I
3.计算1/2 -1/5+1/8-1/11 ...前n项的和
输入1个正整数n(n<=10),计算s的前n项的和(保留3位小数).
s=1/2-1/5+1/8-1/11 +....
例:括号内是说明
输入:
7 (n=7)
输出:0.397
我算不到预期结果,不知道哪里出错了。
我的答案是这样的:
#include<stdio.h>
void main()
{
{int time1,time2;
int mins,hours;
scanf("%d",&time1);
scanf("%d",&time2);
scanf("%d",&mins);
scanf("%d",&hours);
printf("%d%d",mins,hours);}
int time1 =time1/100*60+time1%100;
int time2=time2/100*60+time2%100;
int mins=(time2-time1)%60;
int hours=(time2-time1-mins)/60;
if(mins>=60)
{
mins-=60;
hours+=1;
};
printf("The train journey time is %d hours,%d mins");
}