C++ Program to Generate Random Numbers between 0 and 100

By | 24.12.2016

Generate Random Numbers


Write a C++ Program to Generate Random Numbers between 0 and 100. Here’s simple C++ Program to Generate Random Numbers between 0 and 100 in C++ Programming Language.


Here is source code of the C++ Program to Generate Random Numbers. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.


SOURCE CODE : :


/*  C++ Program to Generate Random Numbers between 0 and 100  */

#include<iostream>
#include<stdlib.h>
using namespace std;

int main()
{
    int i;          //loop counter
    int num;        //store random number

    cout<<"Generating Random Numbers Below :: \n\n";
    for(i=1;i<=10;i++)
    {
        num=rand()%100; //get random number
        cout<<" "<<num<<" ";
    }

    cout<<"\n";

    return 0;
}

Output : :


/*  C++ Program to Generate Random Number between 0 and 100  */

Generating Random Numbers Below ::

 41  67  34  0  69  24  78  58  62  64

Process returned 0

Above is the source code for C++ Program to Generate Random Number between 0 and 100 which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

3.1 7 votes
Article Rating
Subscribe
Notify of
guest
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Coda Ardy

hi,
thanks for your great site!
I was wondering if we want to generate a random number between 0 and 100, it means [0,100], so it’s should contain also 100. if so, we should do “rand()%101”, is that right?!

Dor1an

yes, here it is in the interval [0; 100[

Last edited 7 months ago by Dor1an
bhavesh ajani

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

int main(){
    srand(time(0));
    cout<<“Random numbers generated between 1 and 100:”<<(rand()%100);
}