- //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;
- }
复制代码
|