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.4 23 votes
Article Rating
Category: Basic Programs C++ Programming Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest

9 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 3 years 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);
}

Bilal Hassan

I am searching for program that generate random number from -100 to 100
and also show the minimum and maximum number

Jaffer

What is the use of

Fateh Ahsan

I didn’t get this, What does mean by random numbers between 0 to 100, every time i run this code the output remain same then how could we say that it’s a random number?

Oscar Olsen

need to include

srand(time(0));

into your code then you’ll get a random number everytime without having to rebuild. It’s the first thing I included in the main function.

Oscar Olsen

also include header:

#include <ctime>

Hulya

Solutions very good