943,777 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 680
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 29th, 2009
0

c project

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
atreyeepal1 is offline Offline
4 posts
since Jul 2009
Jul 29th, 2009
0

Re: c project

Reputation Points: 651
Solved Threads: 35
Posting Whiz in Training
yellowSnow is offline Offline
201 posts
since Jul 2009
Jul 29th, 2009
0

Re: c project

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
Reputation Points: 22
Solved Threads: 12
Junior Poster
Dream2code is offline Offline
144 posts
since Jun 2009
Jul 29th, 2009
0

Re: c project

Click to Expand / Collapse  Quote originally posted by Dream2code ...
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
Reputation Points: 769
Solved Threads: 128
Banned
ithelp is offline Offline
1,910 posts
since May 2006
Jul 29th, 2009
0

Re: c project

Click to Expand / Collapse  Quote originally posted by ithelp ...
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.
Reputation Points: 22
Solved Threads: 12
Junior Poster
Dream2code is offline Offline
144 posts
since Jun 2009
Jul 29th, 2009
0

Re: c project

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
atreyeepal1 is offline Offline
4 posts
since Jul 2009
Jul 29th, 2009
0

Re: c project

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.
Reputation Points: 22
Solved Threads: 12
Junior Poster
Dream2code is offline Offline
144 posts
since Jun 2009
Jul 29th, 2009
0

Re: c project

> 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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jul 30th, 2009
0

Re: c project

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
atreyeepal1 is offline Offline
4 posts
since Jul 2009
Jul 30th, 2009
0

Re: c project

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
atreyeepal1 is offline Offline
4 posts
since Jul 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Simple Question regarding char Ptrs
Next Thread in C Forum Timeline: Start Learning C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC