I am doing an assignment where I am trying to get random numbers between 1-10.
But I dont want any number to come more than one time. I am using the following code.
Code:
#include <stdlib.h>
#include <stdio.h>
#include<conio.h>
#include <time.h>
void randomsort ();
int main ()
{
clrscr();
randomsort();
getchar();
return 0;
}
void randomsort()
{
int b[10],i;
time_t t;
srand ((unsigned) time(&t));
for(i=1;i<=10;i++)
{
b[i]= rand() % 11;
if (b[i]==b[i])
printf ("%d\n",b[i]);
}
}
It chooses random numbers but the output is like
0
2
0
2
2
1
1
9
9
It is giving me the number more than ones.
How can I solve this problem? Please help.