CODING IN C LANGUAGE ONLY Write the C program that solves th
CODING IN C LANGUAGE ONLY
Write the C program that solves the problem:
Write a program that simulates a die with six faces.
The program is rolling the die for the user, but the user needs to specify how many times the die needs to be rolled.
Have the program print out how many times a certain face came up, along with the percentage out of 100%.
Solution
#include <stdlib.h>
#include <stdio.h>
int Random(int Max) {
return ( rand() % Max)+ 1;
}
int main(void) {
// your code goes here
int count;
printf(\"How many times you want to roll the dice?\");
scanf(\"%d\",&count);
int arr[6] = {0,0,0,0,0,0};
int face;
int i=0;
for(i=0;i<count;i++)
{
face = Random(6);
arr[face-1]++;
}
for(i=0;i<6;i++)
{
printf(\"%d came up %d times with %f of percentage\ \",i+1,arr[i],arr[i]*100.0/count);
}
return 0;
}
