program to generate random number in range || C++p
In this, we are going see a program to Generate Random Number in Range in C++ Programming Language.
 


The Code given below can be used in TURBO C++ Compilers: -

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>

void main()
{
	int n,max,min,num,m;
	cout<<"Enter the number of Random Numbers you want : ";
	cin>>n;
	cout<<"Enter the Maximum value of Random Number : ";
	cin>>max;
	cout<<"Enter the Minimum value of Random Number : ";
	cin>>min;
	cout<<n<<" Random Numbers from "<<min<<" to "<<max<<" are :- \n";
	for(m=1;m<=n;m++)
	{
		num=rand()%(max-min+1);
		cout<<num<<endl;
	}
	getch();
	clrscr();
}


The Code given below can be used in gcc/g++ Compilers: -

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

int main()
{
	int n,max,min,num,m;
	cout<<"Enter the number of Random Numbers you want : ";
	cin>>n;
	cout<<"Enter the Maximum value of Random Number : ";
	cin>>max;
	cout<<"Enter the Minimum value of Random Number : ";
	cin>>min;
	cout<<n<<" Random Numbers from "<<min<<" to "<<max<<" are :- \n";
	for(m=1;m<=n;m++)
	{
		num=rand()%(max-min+1);
		cout<<num<<endl;
	}
	return 0;
}


#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post