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.
Answer Posted / 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 |
Post New Answer View All Answers
Tell me what is the purpose of 'register' keyword in c language?
In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between 1 and N.Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.
Can main () be called recursively?
Suggesting that there can be 62 seconds in a minute?
What are lookup tables in c?
Explain how do you print only part of a string?
What do the functions atoi(), itoa() and gcvt() do?
what is a function method?give example?
What is a list in c?
What are 3 types of structures?
Compare and contrast compilers from interpreters.
Explain what is the stack?
When should the register modifier be used? Does it really help?
Can we add pointers together?
What is scope rule in c?