Hi Stober!
Thanks for the idea but that doesn't solve my problem. I need to use the rand() function because I need random numbers at those array location, I know that at array[5] i have an integer 6, that's not random number. If you could look into my new code below and tell me what am i missing to make it work that would be great, please suggest...
thanks a lot
vashudev
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
int main(){
srand( time ( NULL ) );
int i = 0, j, k, iarray[10], randNum, counter = 0, numChecks = 0;
iarray[i] = rand()%10;
for( i = 1; i < 10; i++ ){
randNum = rand()%10;
iarray[i] = randNum;
printf("The number created each time for the for loop ");
printf( "%-5d\n", iarray[i] );
j = 0;
while( j<i ){
if( iarray[i] == iarray[j] )
while( randNum == iarray[j] ){
randNum = rand()%10;
numChecks++;
}//end inner while
j++;
iarray[i] = randNum;//()%10;
}// outer while
}//end for
for( k = 0; k < 10; k++ ){
printf( "%-5d", iarray[k] );
if( ++counter%10 == 0 )
printf( "\n\n" );
}
printf("The total number of checks performed is: " );
printf( "%-5d", numChecks );
printf( "\n" );
system( "PAUSE" );
return 0;
}
: : Hi All!
: : I need to create and store a unique set of 100 integers from 0 to 99.
:
: just create a loop and store the loop counter in an array. There is no need for rand(), in fact it will only make thig worse.
:
: int array[100];
: for(int i = 0; i < 100; i++)
: array[i] = i;
:
:
:
: