黑马程序员技术交流社区
标题:
C语言基础day05 作业,怎么写随机数?
[打印本页]
作者:
Chen_Mx
时间:
2016-1-4 23:38
标题:
C语言基础day05 作业,怎么写随机数?
题目是这样的:
请写1个支付宝接龙红包程序.
随机产生1-100的随机数,作为红包金额.
让用户不断的去猜,直到猜正确为止.最后发给用户的红包金额是 红包金额/猜得次数.
不知道随机数要怎么来取? 求指点。
作者:
李博文
时间:
2016-1-5 00:22
//1. 请写1个支付宝接龙红包程序.
//随机产生1-100的随机数,作为红包金额.
//让用户不断的去猜,直到猜正确为止.最后发给用户的红包金额是 红包金额/猜得次数.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
int computer = arc4random_uniform(100) + 1;
printf("请猜红包金额:");
int input = 0;
scanf("%d",&input);
int count = 1;
while (input != computer) {
count++;
printf("请继续猜:");
int input2 = 0;
scanf("%d",&input2);
input = input2;
}
printf("恭喜你,你收到%d块钱。\n",computer/count);
return 0;
}
复制代码
作者:
x_starry
时间:
2016-1-5 09:24
好强大,!!!!
作者:
15931110616
时间:
2016-1-5 11:46
挺厉害的嘛
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2