2005/03/06 | C的第一个小游戏——猜数字
类别(其其它它) | 评论(0) | 阅读(149) | 发表于 17:09
本来很久没有碰C了,今天突然翻到以前在废纸上写的一小段代码
正好现在有了条件,把它调试通过了,发上来。

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
main(){
    int a,b;
    time_t c;
    srand((unsigned) time(&c));
    a=rand()%21;
    printf("Please key in a number from 0 to 20\n");
    printf("=");
    scanf("%d",&b);
    while(b!=a){
        if(b>a){
            printf("more\n");
            printf("=");
        }else if(b<a){
            printf("less\n");
            printf("=");
        }
        scanf("%d",&b);
    } 
    printf("Righr! The random number is %d",a); 
}
0

评论Comments

日志分类
首页[164]
我的网志[105]
文章随笔[10]
=flash=[19]
PHP[2]
Photoshop[5]
Web 标准[2]
其其它它[21]