About the two ways to throw the dice, just and a classmate chatting up,
I just made it. Two methods, all very simple!
In this record,
The first method is entered once each time:
#include <stdio.h>
#define N 5
int main () {
Define a variable to hold the number of dice
int num;
Define the number variables that appear
int count_1=0, count_2=0, count_3=0, count_4=0, count_5=0, count_6=0;
for (int i=1; i<=n; i++) {
printf ("Please enter the number of the dice to be thrown at%d times: \ n", i);
scanf ("%d", &num);
if (num==1) {
count_1++;
}else if (num==2) {
count_2++;
}else if (num==3) {
count_3++;
}else if (num==4) {
count_4++;
}else if (num==5) {
count_5++;
}else if (num==6) {
count_6++;
}//here because you entered it once, so you don't need to judge not 1-6,
}
printf ("1 occurrences of%d\n2 occurrences of the number of occurrences of the number of times%d\n3 appears%d\n4 the number of occurrences of the number of%d\n5 occurrences%d\n6 the number of occurrences%d\n", Count_1,count_2,count_3,count_4, Count_5,count_6);
return 0;
}
The second method, with random numbers:
#include <stdio.h>
#include <stdlib.h>
#define N 100
int main () {
int count_1=0, count_2=0, count_3=0, count_4=0, count_5=0, count_6=0;
for (int i=1; i<=n; i++) {
int num= Arc4random_uniform (6) +1; (N) The random 0~n-1,
if (num==1) {
count_1++;
}else if (num==2) {
count_2++;
}else if (num==3) {
count_3++;
}else if (num==4) {
count_4++;
}else if (num==5) {
count_5++;
}else if (num==6) {
count_6++;
}else{
i--;
Continue
}
}
printf ("1 occurrences of%d\n2 occurrences of the number of occurrences of the number of times%d\n3 appears%d\n4 the number of occurrences of the number of%d\n5 occurrences%d\n6 the number of occurrences%d\n", Count_1,count_2,count_3,count_4, Count_5,count_6);
return 0;
}
Two ways to throw a dice problem