#include<stdio.h>
int Difference(int a, int b,int c);
/*function main begins*/
int main(void)
{
int x,y,z;
printf(“enter the hour :\n”);
scanf(“%d”,&x);
printf(“enter the Minutes:\n”);
scanf(“%d”,&y);
printf(“enter the seconds:\n”);
scanf(“%d”,&z);
while(x<0||x>=12||y<0||y>=60||z<0||z>=60){
printf(“time is illeag,Please input again\n”);
scanf(“%d%d%d\n”,&x,&y,&z);
}
Difference(x,y,z);
return 0;
}
int Difference(int a, int b, int c)
{
int total;
total= a*60*60+b*60+c;
printf(“total time is %d\n”,total);
return total;
}
我运行上面这个程序的时候,电脑cpu利用率将近达到100%,把while循环去掉之后就快了很多.while语句不会这么影响性能吧.
>> 本文固定链接: http://www.vcgood.com/archives/3126
反复循环浪费资源