一个C++的程序问题
编写一个程序,当用户输入两个时刻以后,求出这两个时刻的时间差(按秒计算)并打印到屏幕上?急求大侠的帮助~~~...
编写一个程序,当用户输入两个时刻以后,求出这两个时刻的时间差(按秒计算)并打印到屏幕上?
急求大侠的帮助~~~ 展开
急求大侠的帮助~~~ 展开
展开全部
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int h1,m1,s1,h2,m2,s2,sum;
cout<<"enter a time :";
cin>>h1>>m1>>s1;
cout<<"\nenter another time :";
cin>>h2>>m2>>s2;
sum=fabs(h2-h1)*3600+fabs(m2-m1)*60+fabs(s2-s1);
cout<<endl<<sum<<endl;
}
#include <cmath>
using namespace std;
int main()
{
int h1,m1,s1,h2,m2,s2,sum;
cout<<"enter a time :";
cin>>h1>>m1>>s1;
cout<<"\nenter another time :";
cin>>h2>>m2>>s2;
sum=fabs(h2-h1)*3600+fabs(m2-m1)*60+fabs(s2-s1);
cout<<endl<<sum<<endl;
}
展开全部
#include<stdio.h>
void main()
{
int h1,m1,s1,h2,m2,s2,output;
printf("Input first time(H:M:S):");
scanf("%d:%d:%d",&h1,&m1,&s1);
while(h1>23 || h1<0 || m1>59 || m1<0 || s1>59 || s1<0)
{
printf("Error,input again:");
scanf("%d:%d:%d",&h1,&m1,&s1);
}
printf("Input second time(H:M:S):");
scanf("%d:%d:%d",&h2,&m2,&s2);
while(h2>23 || h2<0 || m2>59 || m2<0 || s2>59 || s2<0)
{
printf("Error,input again:");
scanf("%d:%d:%d",&h2,&m2,&s2);
}
output=(h2*3600+m2*60+s2)-(h1*3600+m1*60+s1);
printf("%d:%d:%d - %d:%d:%d = %d",h2,m2,s2,h1,m1,s1,output);
}
void main()
{
int h1,m1,s1,h2,m2,s2,output;
printf("Input first time(H:M:S):");
scanf("%d:%d:%d",&h1,&m1,&s1);
while(h1>23 || h1<0 || m1>59 || m1<0 || s1>59 || s1<0)
{
printf("Error,input again:");
scanf("%d:%d:%d",&h1,&m1,&s1);
}
printf("Input second time(H:M:S):");
scanf("%d:%d:%d",&h2,&m2,&s2);
while(h2>23 || h2<0 || m2>59 || m2<0 || s2>59 || s2<0)
{
printf("Error,input again:");
scanf("%d:%d:%d",&h2,&m2,&s2);
}
output=(h2*3600+m2*60+s2)-(h1*3600+m1*60+s1);
printf("%d:%d:%d - %d:%d:%d = %d",h2,m2,s2,h1,m1,s1,output);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询