#include <stdio.h>
#include <time.h>
int arraySum(const int * const a, int n) {
int i = 0, sum = 0
for (i <ni++) {
sum += a[i]
}
return sum
}
int main(int argc, char *argv[]) {
int i = 0
int a[3] = {0}
int sum = 0
srand((int)time(0))
for (i <3i++) {
a[i] = (rand() % 6)+1
}
printf("%d,%d,%d\n", a[0],a[1],a[2])
sum = arraySum(a, sizeof(a)/sizeof(a[0]))
// 3, 4, 5, 6, 7, 8, 9,10, 小
// 11,12,13,14,15,16,17,18 大
if (sum <11) {
printf("小\n")
} else {
printf("大\n")
}
return 0
}
#include<stdio.h>#include<stdlib.h>
#include<time.h>
int main(void)
{
int bi[3] //乙的三个骰子的点数
int i
srand((unsigned)time(NULL)) //播时间种子,产生随机数
for (i = 0 i < 3 i++)
{
ai[i] = rand() % 6 + 1 //随机产生1-6的点数
bi[i] = rand() % 6 + 1
}
printf("甲的点数:")
for (i = 0 i<3 i++)
{
printf("%d ", ai[i])
}
printf("\n乙的点数:")
for (i = 0 i<3 i++)
{
printf("%d ", bi[i])
}
if (ai[0] + ai[1] + ai[2]>bi[0] + bi[1] + bi[2])
{
printf("\n\n甲获胜.\n")
}
else{
printf("\n\n乙获胜.\n")
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)