How to write a code for random pick from 1-1000 numbers?
The output should contain the 10 numbers from the range
1-1000 which should pick randomly, ie ,for each time we run
the code we should get different outputs.

Answers were Sorted based on User's Feedback



How to write a code for random pick from 1-1000 numbers? The output should contain the 10 numbers f..

Answer / navdeep singh

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main(void)
{
int i;

randomize();
printf("Ten random numbers from 0 to 1000\n\n");
for(i=0; i<10; i++)
printf("%d\n", rand() % 100);
return 0;

}

Is This Answer Correct ?    15 Yes 7 No

How to write a code for random pick from 1-1000 numbers? The output should contain the 10 numbers f..

Answer / kameshwar

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int i;
srand(time(NULL));
printf("\n Ten random numbers between 1 and 1000 are \n");
for(i=0;i<10;i++)
printf("%d ",(rand() % 1000) + 1);
return EXIT_SUCCESS;
}

Is This Answer Correct ?    5 Yes 0 No

How to write a code for random pick from 1-1000 numbers? The output should contain the 10 numbers f..

Answer / kap

it is not the correct answer because the range they asked 0-
1000 so need to to %1000. :-)

Is This Answer Correct ?    3 Yes 0 No

How to write a code for random pick from 1-1000 numbers? The output should contain the 10 numbers f..

Answer / rama krishna

Execute and verify it once

Is This Answer Correct ?    2 Yes 0 No

How to write a code for random pick from 1-1000 numbers? The output should contain the 10 numbers f..

Answer / nischal e rao

The best way to solve this problem would be to create a hash
function and apply the current time to as the argument to
the hash function. the hash function should be designed to
return a number between 1 to 1000.

Is This Answer Correct ?    1 Yes 0 No

How to write a code for random pick from 1-1000 numbers? The output should contain the 10 numbers f..

Answer / sharan

if the randomize(); doesn't work
replace it with srand ((unsigned) time (NULL));

Is This Answer Correct ?    2 Yes 2 No

How to write a code for random pick from 1-1000 numbers? The output should contain the 10 numbers f..

Answer / abhradeep chatterjee

the above answer is correct.

Is This Answer Correct ?    3 Yes 4 No

How to write a code for random pick from 1-1000 numbers? The output should contain the 10 numbers f..

Answer / abhradeep chatterjee

I am Sorry, I executed the Code and it does not work.
Thanks to Rama Krishna.

Is This Answer Correct ?    1 Yes 2 No

How to write a code for random pick from 1-1000 numbers? The output should contain the 10 numbers f..

Answer / rama krishna

First program is wrong ,randomize is undefined you just
check it.

Is This Answer Correct ?    0 Yes 1 No

How to write a code for random pick from 1-1000 numbers? The output should contain the 10 numbers f..

Answer / umesh koodali

So anybody know the right answer?

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More C Interview Questions

Explain null pointer.

0 Answers  


Explain what are its uses in c programming?

0 Answers  


write a program to insert an element at the specified position in the given array in c language

5 Answers   Appin, IBM,


Is main() is used in the program,,see below example? void main() { int i; for(i=0;i<10;i++) main(); } Then what is the output of the program?

6 Answers  


Explain continue keyword in c

0 Answers  






Write a programm such that if user enter 11.25 it roundup to 11 but if user enter 11.51 upto 11.99 it will round up to 12 i.e.;convert the floting point value into integer format as explain above..

2 Answers  


What is typeof in c?

0 Answers  


Write a program to find given number is even or odd without using any control statement.

2 Answers  


Iam a B.Tech graduate and completed my engineering in 2009, from 2005 to 2009 and after that i had done nothing.Now i want to do job and get into BPO field . Friends give me suggestions as what to say in interview... if they ask me that what would you had done ... these many years without doing job ??????? pls urgent

0 Answers  


Why is sprintf unsafe?

0 Answers  


What is c standard library?

0 Answers  


How can I run c program?

0 Answers  


Categories