Friday, 21 December 2012

Random numbers generation c++ program

#include<iostream>
#include<conio.h>
using namespace std; 
void swap(int &a,int &b) 
int main()
{int n,s,i,p=1;
cout<<"The number of numbers u want in random  :";     cin>>n;
int a[n],j=1; 
a[0]=p;
     for(i=++p;i<=n;i++,j++)
     {
     a[j]=i;
     if(j%2!=0)
     swap(a[j-1],a[j]);
     } 

 cout<<"\nRandom list generated \n";
 for(j=0;j<n;j++)
 cout<<a[j]<<"  "; 
getch(); 
}

void swap(int &a,int &b)
{int temp=a;
a=b;
b=temp;
}

No comments:

Post a Comment