本帖最后由 ldhmyf 于 2012-11-20 18:55 编辑
我也是初学者,非常感谢老师的书,很浅显易懂,让我这个完全没接触过一点语言的人也能看的懂。关于老师留下的2分钟倒计时的题目,我用while跟for两种循环各写了一段代码,希望大家多交流下心得。
while循环
#include <stdio.h>
int main()
{
int a,b;
a=2;
while(a>=0)
{
b=59;
while(b>=0)
{
system("cls");
if(b<=9)
printf("%d:0%d",a,b);
else
printf("%d:%d",a,b);
b=b-1;
sleep(200);
}
a=a-1;
}
sleep(5000);
return 0;
}
for循环
#include <stdio.h>
int main()
{
int a,b;
for(a=2;a>=0;a--)
{
for(b=59;b>=0;b--)
{
system("cls");
if(b<=9)
printf("%d:0%d",a,b);
else
printf("%d:%d",a,b);
sleep(100);
}
}
sleep(5000);
return 0;
}
另外现在就下了前三章的PDF书,第四章开始不知道哪里有下了。
|