c project

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2009
Posts: 4
Reputation: atreyeepal1 is an unknown quantity at this point 
Solved Threads: 0
atreyeepal1 atreyeepal1 is offline Offline
Newbie Poster

c project

 
0
  #1
Jul 29th, 2009
i'm tying 2 describe my problem here.plz solve it for me..

1. generate a random number b2in 0 and 1 (r);
2. do t=r*2.5 ;
3. do w= t/100
4. keep track of all t1,t2,t3.... in an array and do the sum S=(t1+t2+t3......) ;
5. repeat steps 1,2,3,4, till S<100
6. store the corresponding w1,w2,w3... in another array/ heap
7. sort them in ascending order.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 201
Reputation: yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold 
Solved Threads: 35
yellowSnow's Avatar
yellowSnow yellowSnow is offline Offline
Posting Whiz in Training

Re: c project

 
0
  #2
Jul 29th, 2009
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 139
Reputation: Dream2code is an unknown quantity at this point 
Solved Threads: 11
Dream2code's Avatar
Dream2code Dream2code is offline Offline
Junior Poster

Re: c project

 
0
  #3
Jul 29th, 2009
its not a place that we can solve your homework problem.

still take some hints and show ur effort , the code you have tried so far.Then only you can expect something from this forum.

1)rand() function is used to generate random numbers.

  1. int y=rand();
  2. int num=(y-1)/y;

then you proceed with your next steps...

Thanks,
DP
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,855
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 120
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: c project

 
0
  #4
Jul 29th, 2009
Originally Posted by Dream2code View Post
its not a place that we can solve your homework problem.

still take some hints and show ur effort , the code you have tried so far.Then only you can expect something from this forum.

1)rand() function is used to generate random numbers.

  1. int y=rand();
  2. int num=(y-1)/y;

then you proceed with your next steps...

Thanks,
DP
Num will be always 0
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 139
Reputation: Dream2code is an unknown quantity at this point 
Solved Threads: 11
Dream2code's Avatar
Dream2code Dream2code is offline Offline
Junior Poster

Re: c project

 
0
  #5
Jul 29th, 2009
Originally Posted by ithelp View Post
Num will be always 0
Hey sory i forgot about type casting as i was giving a dummy code.
  1.  
  2. int y=rand();int num=(y-1)/y;int y=rand();
  3. float num=(float) (y-1)/y;


it should be type cased to float.
Thanks,
DP
Last edited by Dream2code; Jul 29th, 2009 at 5:42 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 4
Reputation: atreyeepal1 is an unknown quantity at this point 
Solved Threads: 0
atreyeepal1 atreyeepal1 is offline Offline
Newbie Poster

Re: c project

 
0
  #6
Jul 29th, 2009
i tried but everytime it shows 0.00000
and no other value

i tried it another way....
with the srand() function
but all it gives between 0 and 1 is 0
but what i want is 0.1 or 0.2... something like that
how can i get it?
and it's notlike i haven't work with the algo
just i couldn't
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 139
Reputation: Dream2code is an unknown quantity at this point 
Solved Threads: 11
Dream2code's Avatar
Dream2code Dream2code is offline Offline
Junior Poster

Re: c project

 
0
  #7
Jul 29th, 2009
Originally Posted by atreyeepal1 View Post
i tried but everytime it shows 0.00000
and no other value

i tried it another way....
with the srand() function
but all it gives between 0 and 1 is 0
but what i want is 0.1 or 0.2... something like that
how can i get it?
and it's notlike i haven't work with the algo
just i couldn't
try like this...

  1. int y=rand(); //y should be an integer
  2. float num=(float)(y-1)/y; //num should be a float and its typecasted
  3. printf("%d\t%f",y,num);

if you want to know more about random number generators
goto:

http://www.eternallyconfuzzled.com/a..._art_rand.aspx
Last edited by Dream2code; Jul 29th, 2009 at 10:45 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: c project

 
0
  #8
Jul 29th, 2009
> i tried but everytime it shows 0.00000
> and no other value
> i tried it another way....
Look, just post some actual code, and describe what doesn't work in that particular program.

Don't just post "I tried x y and z, and it didn't work".
We can't help you fix your mistakes if you never show us any code to begin with.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 4
Reputation: atreyeepal1 is an unknown quantity at this point 
Solved Threads: 0
atreyeepal1 atreyeepal1 is offline Offline
Newbie Poster

Re: c project

 
0
  #9
Jul 30th, 2009
if i want 2 create 40 random numbers
logically it should be done by a for loop
i tried as follows
but it shows 1 number.
i can't understand my faults

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<time.h>
  4.  
  5. int random(void)
  6. {
  7. return(1+rand()%3);
  8. }
  9.  
  10. int main(void)
  11. {
  12. int i;
  13. srand(time(0));
  14. for(i=0;i<40;i++);
  15. printf("the number is %d\n",random());
  16. }
Last edited by John A; Jul 30th, 2009 at 3:05 pm. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 4
Reputation: atreyeepal1 is an unknown quantity at this point 
Solved Threads: 0
atreyeepal1 atreyeepal1 is offline Offline
Newbie Poster

Re: c project

 
0
  #10
Jul 30th, 2009
i tried to the algo as follows
i've changed the algo a bit
1.r=1+rand()%3;
2.t=r*1.25;
3.do w= t/100;
4. keep track of all t1,t2,t3.... in an array /* upto this is ok*/
and do the sum S=(t1+t2+t3......) ;/*from this step i can't do*/
5. repeat steps 1,2,3,4, till S<100
6. store the corresponding w1,w2,w3... in another array/ heap
7. sort them in ascending order.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC