程序一:
将你条件稍微改了一下
起飞时间 抵达时间
8:00 am 10:16 pm
9:43 am 11:52 pm
11:19 am 1:31 pm
12:47 pm 3:00 pm
2:00 pm 4:08 pm
3:45 pm 5:55 pm
7:00 pm 9:20 pm
9:45 pm 11:58 pm
#include<stdio.h>
void main()
{
int h,m;
printf("Enter a 24-hour time :");
scanf("%d:%d",&h,&m);
int count;
count = 60*h+m;
if(count<=(8*60))
{
if((8*60-count)<=(count+2*60+15))
printf("Closest departure time is 8:00 am ,arriving at 10:16 pm");
else
printf("Closest departure time is 9:45 pm ,arriving at 11:58 pm");
}
if(count>(8*60)&&count<=(9*60+43))
{
if((count-(8*60))<=((9*60+43)-count))
printf("Closest departure time is 8:00 am ,arriving at 10:16 pm");
else
printf("Closest departure time is 9:43 am ,arriving at 11:52 pm");
}
if(count>(9*60+43)&&count<=(11*60+19))
{
if((count-(9*60+43))<=((11*60+19)-count))
printf("Closest departure time is 9:43 am ,arriving at 11:52 pm");
else
printf("Closest departure time is 11:19 am ,arriving at 1:31 pm");
}
if(count>(11*60+19)&&count<=(12*60+47))
{
if((count-(11*60+19))<=((12*60+47)-count))
printf("Closest departure time is 11:19 am ,arriving at 1:31 pm");
else
printf("Closest departure time is 12:47 am ,arriving at 3:00 pm");
}
if(count>(12*60+47)&&count<=(14*60))
{
if((count-(12*60+47))<=((14*60)-count))
printf("Closest departure time is 12:47 am ,arriving at 3:00 pm");
else
printf("Closest departure time is 2:00 pm ,arriving at 4:08 pm");
}
if(count>(14*60)&&count<=(15*60+45))
{
if((count-(14*60))<=((15*60+45)-count))
printf("Closest departure time is 2:00 pm ,arriving at 4:08 pm");
else
printf("Closest departure time is 3:45 pm ,arriving at 5:55 pm");
}
if(count>(15*60+45)&&count<=(19*60))
{
if((count-(15*60+45))<=((19*60)-count))
printf("Closest departure time is 3:45 pm ,arriving at 5:55 pm");
else
printf("Closest departure time is 7:00 pm ,arriving at 9:20 pm");
}
if(count>(19*60)&&count<=(21*60+45))
{
if((count-(19*60))<=((21*60+45)-count))
printf("Closest departure time is 7:00 pm ,arriving at 9:20 pm");
else
printf("Closest departure time is 9:45 pm ,arriving at 11:58 pm");
}
if(count>21*60+45)
printf("Closest departure time is 9:45 pm ,arriving at 11:58 pm");
}
程序二:
#include<stdio.h>
void main()
{
int day,month,year;
printf("输入日期:");
scanf("%d/%d/%d",&month,&day,&year);
int min_day,min_month,min_year;
min_day = day;
min_month = month;
min_year =year;
while(day!=0||month!=0||year!=0)
{
if(year<min_year)
{
min_day = day;
min_month = month;
min_year =year;
}
if(year==min_year)
{
if(month<min_month)
{
min_day = day;
min_month = month;
}
if(month==min_month)
{
if(day<min_day)
min_day = day;
}
}
scanf("%d/%d/%d",&month,&day,&year);
}
printf("%d/%d/%02d is the earliest date\n",min_month,min_day,min_year);
}
程序三:
#include<stdio.h>
#include <string.h>
void main()
{
char str[100];
int i;
int count = 0;
int x = 0;
float ave;
bool flag = false;
printf("Enter a sentence:");
gets(str);
for(i = 0; i<100; i++)
{
if(str[i]=='\0')
break;
if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))
{
count++;
flag = true;
}
else
{
if(flag)
x++;
}
}
ave=float(count)/x;
printf("%f\n",ave);
}
[此贴子已经被作者于2018-4-14 20:44编辑过]