rand()

giving same value every time 41, 18467 and so the values are same

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  #include<iostream>
#include<stdlib.h>
using namespace std;

main()
{
int z,i;
int a[100];
	for(i = 0; i<100; i++)
	{
		a[i] = rand();
	}
	cout<<"Please Enter Positive Integer ";
	cin>>z;
	int found = 0;	
	for(i = 0; i<100; i++)
	{
		if(z == a[i])
		{
			found = 1;
			break;
		}
	}
	if(found == 1)
	{
		cout<<"We Found Your The Integer At Position "<<i;
	}
	else
	{
		cout<<"The Number Was Not Found ";
	}
	
	cout<<"\n\n All Number Are ";
	for(i = 0; i<100; i++)
	{
		cout<<a[i]<<", ";
	}
}
please describe it in a beginner level i am new in c++ 

You forgot to call srand() at the start of main().

 
srand (time(NULL));


requires the header
 
#include <ctime> 


Same topic:
http://www.cplusplus.com/forum/beginner/216062/#msg1002595

Posting your question twice won't help you.
Topic archived. No new replies allowed.