kumud
kumud

Reputation: 43

how to select few numbers from randomly generated numbers using C

#include<stdio.h>
#include<stdlib.h>
void main()
{
    int i,N;
    N=20;
    printf("Random data points are: \n");
    for(i=0;i<N;i++)
    {
         printf("%d \n", rand() %100);
    }
    getch();
}

suppose random data points are : 6 8 9 17 19 5 4 1 14 10 9 .upto 20..

how can i select 'k' numbers from this output generated by Rand function. for example: if i take user input k=4 then the program must return 4 values from this output..

please guide me..thank u

Upvotes: 0

Views: 43

Answers (1)

GorvGoyl
GorvGoyl

Reputation: 49150

use scanf("%d",&N);

printf("Random data points are: \n");
scanf("%d",&N);
 for(i=0;i<N;i++)
    {
         printf("%d \n", rand() %100);
    }

Upvotes: 2

Related Questions