hi, i need generate 5 diferent nubmers from 1 to 10, without repeating.
Code:
#include<stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 5
void main()
{
int i,j,index;
int mas[N];
int random_integer;
srand ( time(NULL) );
for(index=0; index<5; index++){
random_integer = (rand()%10)+1;
mas[i]=random_integer;
j=0;
for ( i = 0; i< 5; i++ ) {
if ( mas[j] == random_integer );
break;
}
if ( j == i )
mas[i] = random_integer;
printf("%5d", mas[i]);
}
}
i can`t understand how i should compare array elements, so in the output wouldnt be two indetical elements. Thank you