C Program to Emulate N Dice Roller

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.

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  5. int main(int argc, char **argv) {
  6.     printf("Enter the number of dice: ");
  7.     int n, i;
  8.     scanf("%d", &n);
  9.     printf("The values on dice are: ( ");
  10.     for (i = 0; i < n; i++)
  11.         printf("%d ", (rand() % 6) + 1);
  12.     printf(")");
  13.     return 0;
  14. }


$ 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.


Here’s the list of Best Books in C Programming, Data Structures and Algorithms.

If you find any mistake above, kindly email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.