Member Avatar for HASHMI007

i make this progrm . first i generate this of 100 number .
then user cheaked the user how many time number is repeated in this series.
but i want random series of 100 number .
please check it & how to create a random series in this program.

#include<iostream.h>
#include<conio.h>
void generateData(int num []);
void printArray(int num[]);
int searchArray(int num[],int y);
int main()
{
int num[100],y;
generateData(num );
printArray(num);
searchArray(num,y)  ;
return -1;
}

void generateData(int num [100])
{


	for(int count=0;count<100;count++)
	{
		num[count]=count;
	  cout<<num[count]<<" ";

	}
	getch();clrscr();


}
void printArray(int num[100])
{
	 int count=0;
	for(int row=1;row<=10;row++)
	{
		for(int col=1;col<=row;col++)
		{
			for(;count<100 && count<10*row ;count++)
			{
			 cout<<num[count]<<"   ";
			}
		 }cout<<"\n";
	  }
}
int searchArray(int num[100],int y)
{
	 cout<<"enter the value THAT  u want fine taht how many it repeat that : ";
	 cin>>y;
	 cout<<endl;
	 int counter=0;
	for(int count=0;count<100;count++)
	{

	  if(y==num[count])
	  {
		counter++;
	  }

	}
	if(counter>0)
	{
		cout<<endl<<endl<<"the enter no is :"<<counter<<" times in table";
	}
	else
	{
	return -1;
	}
}

If you want random numbers, use srand and rand from cstdlib, and time from ctime:

http://www.cplusplus.com/reference/clibrary/cstdlib/srand/
http://www.cplusplus.com/reference/clibrary/cstdlib/rand/
http://www.cplusplus.com/reference/clibrary/ctime/time/

This fills up an array of 5 integers with values ranging from 0 to 9, inclusive:

int a[5];
srand(time(0));
for(int i = 0; i < 5; i++)
{
    a[i] = rand() % 10;
}
// a[] now has random numbers in it.
Member Avatar for HASHMI007

thnk u

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.