c語言之猜數遊戲:[1]
- 電腦
- 關注:1.32W次
方法/步驟1
(01)寫入所需頭文件#include <stdlib.h>/*隨機函數的申明*/#include <stdio.h> #include <time.h>
(02)所需變量的定義main(){int n,g,c=100,d=0,t;
(03)srand( (unsigned)time( NULL ) );n=rand()%100; /*產生並調用隨機數*/
(04)程序其他部分printf("please input the number you guess between 0 to 100t");scanf("%d",&g);while(g!=n){if(g<n) { d=g; printf("That was small,n please guess it again and input a number between %d to %dn",d,c); scanf("%d",&t);g=t;}if(g>n) {c=g; printf("That was large,n please guess it again and input a number between %d to %dn",d,c) ; scanf("%d",&t);g=t;} }if(g==n)printf("ttt|----------|nttt|you got it|nttt|----------|n");printf("nttt Game overn");getch();}下如為運行結果
特別提示
注意頭文件的寫入
- 文章版權屬於文章作者所有,轉載請註明 https://miaozhigu.com/sm/diannao/qyj962.html