Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Program to find the sum of digits of a given number until the sum becomes a single digit

8 Answers   InterGraph,


Write a program to print ASCII code for a given digit.

0 Answers   EXL, HCL,


Not all reserved words are written in lowercase. TRUE or FALSE?

0 Answers  


what is c language?

2 Answers  


Where we use clrscr in c?

0 Answers  


c program for searching a student details among 10 student details

0 Answers  


Write a main() program that calls this function at least 10 times. Try implementing this function in two different ways. First, use an external variable to store the count. Second, use a local variable. Which is more appropriate?

2 Answers  


Why Modern OS are interrupt driven?Give an example

3 Answers  


Which of the following is not an infinite loop ? a.while(1){ .... } b.for(;;){ ... } c.x=0; do{ /*x unaltered within theloop*/ ... }while(x==0); d.# define TRUE 0 ... while(TRUE){ .... }

7 Answers   TCS,


Just came across this question, felt worth sharing, so here it is I want you to make a C/C++ program that for any positive integer n will print all the positive integers from 1 up to it and then back again! Let's say n=5 I want the program to print: 1 2 3 4 5 4 3 2 1. Too easy you say? Okay then... You can ONLY USE: 1 for loop 1 printf/cout statement 2 integers( i and n) and as many operations you want. NO if statements, NO ternary operators, NO tables, NO pointers, NO functions!

1 Answers  


What is a spanning Tree?

1 Answers   TCS,


What is the use of header?

0 Answers  


Categories