/*

this PROGRAM FINDS RANDOM N NUMBER IN THE INTERVAL OF [1,N]

by Serdar Ulutas

sulutas@eng.marmara.edu.tr

*/

#include "stdio.h"

#include "stdlib.h"

#include "conio.h"

int limit,r[15000]={0};

int ControlR(int i,int num)

    {

    int j,bool=1;

    for(j=0;j

    if(r[j]==num) bool=0;

    if (bool==0) return 0;

    else return 1;

}

void RandomR()

    {

    int i,num;

    for(i=0;i

        {

        num=rand()%limit+1;

        if(ControlR(i,num))// search the array for controlling

        r[i]=num;

        else i--;// finding the number for the index of the previous one

    }

}

void DisplayR(void) // displays the array

    {

    int i;

    for(i=0;i

    printf(" %d ",r[i]);

}

void main()

    {

    int key=1;

    while(key!=27)

        {

        textmode(2);

        srand(time(NULL));

        clrscr();

        printf("Enter the limit : ");

        scanf("%d",&limit);

        RandomR(); // find random n numbers

        DisplayR(); // display the array

        // after this stage you can use selectio

        //     n sort method to sort array

        key=getch();

    }

}