Can someone please give me the follow solutions in C syntax please not c++ Progr
ID: 3765369 • Letter: C
Question
Can someone please give me the follow solutions in C syntax please not c++
Program 1: Write a program that simulates the roll of two dice. The program should call rand to roll first die, and should call rand again to roll the second die. The sum of two values should then be calculated. The sum should be between 2 and 12. Your program should roll the two dice 100 times. Use one dimensional array to tally the numbers of times each sum appears. Print the result in tabular format as shown below:
SUM TOTAL
27
39
410
. .
Note: Use the following statement before you call rand function;
srand( time( NULL ) ); // #include <time.h>, #include<stdlib.h>
Explanation / Answer
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int i,temp,a[13]={};
srand( time( NULL ) );
for(i=0;i<100;i++)
{
temp = (rand() % 11) + 2;
a[temp]++;
}
printf("SUM TOTAL ");
for(i=2;i<13;i++)
printf("%d %d ",i,a[i]);
return 0;
}
output: