This is a C Program to emulate N-dice roller. This can be done by generating random number between 1-6.
Here is source code of the C Program to Emulate N Dice Roller. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char **argv) {
printf("Enter the number of dice: ");
int n, i;
scanf("%d", &n);
printf("The values on dice are: ( ");
for (i = 0; i < n; i++)
printf("%d ", (rand() % 6) + 1);
printf(")");
return 0;
}
Output:
$ gcc EmulateNDice.c $ ./a.out Enter the number of dice: 3 The values on dice are: ( 6 6 5 )
Sanfoundry Global Education & Learning Series – 1000 C Programs.
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data Structures and Algorithms.
Next Steps:
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Practice Computer Science MCQs
- Apply for C Internship
- Buy Computer Science Books
- Practice BCA MCQs
- Watch Advanced C Programming Videos