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
Answer / vignesh1988i
hi... guys... what i think is that we can make use of files... because it is asked that each time we run the code it must generate different numbers..... .. only in file it will be saved pernmently ....
first let us create a file to give a starting number to start the generation....
let us assume that we have created a file named random.txt... in that we have a number 21 (assumption)..
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *pointer,*pointer1;
char ch;
int r=0,n[10],count=0;
pointer=fopen("random.txt","r");
while(1)
{
ch=fgetc(pointer);
if(ch==EOF)
break;
else
r=r+((ch-'0')*10); // to change char to int
}
int j=31;
for(int i=0;i<10;i++)
{
printf("%d",r+12+j);
if(i%2==0)
j+=42;
}
r+=23;
for(i=0;r>0;i++)
{
n[i]=r%10;
r=r/10;
}
pointer1=fopen("random.txt","w");
fflush(stdin);
i=0;
while(1)
{
count++;
ch=n[i]+'0';
if(count!=2)
{
fputc(ch,pointer1);
count++;
}
else
break;
i++;
}
getch();
}
this is only for a sample simple random number generation.....
thank u
Is This Answer Correct ? | 0 Yes | 2 No |
Answer / dayquest
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
int i;
randomize();
printf("\n Ten random numbers between 1 and 1000 are \n");
for(i=0;i<10;i++)
printf("%d ",random(1000)+1);
getch();
}
Is This Answer Correct ? | 0 Yes | 2 No |
How will you allocate memory to a double pointer ?
what r callback function?
What is n in c?
Write a function that accepts two numbers,say a and b and makes bth bit of a to 0.No other bits of a should get changed.
2 Answers Scientific Atlanta, Wipro,
how can i get the output 54321 4321 321 21 1 in c programming........???? pls help......
An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above
1.write a program to merge the arrays 2.write efficient code for extracting unique elements from a sorted list of array?
How do you prevent buffer overflows in C?
what is the need for main function in c?
What does & mean in scanf?
What is a function simple definition?
Write a program to know whether the input number is an armstrong number.