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 / 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

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

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

Post New Answer

More C Interview Questions

what is computer

4 Answers  


Write a simple program to find the size of different basic data types in C.

3 Answers  


How can you dynamically allocate memory in C?

2 Answers  


c program to subtract between two numbers without using '-' sign and subtract function.

1 Answers  


In a switch statement, what will happen if a break statement is omitted?

0 Answers  


the question is that what you have been doing all these periods (one year gap)

0 Answers   HCL,


Was 2000 a leap year?

0 Answers  


How can I get Single byte from 'int' type variable? Can we alter single bit or multiple bits in int type variable? if so, How?

2 Answers  


What are actual arguments?

0 Answers  


Tell us the difference between these two : #include"stdio.h" #include<stdio.h> define in detial.

5 Answers  


How can I do peek and poke in c?

0 Answers  


What's the difference between constant char *p and char * constant p?

0 Answers   Celstream,


Categories