| | |
c project
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2009
Posts: 4
Reputation:
Solved Threads: 0
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.
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.
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.
then you proceed with your next steps...
Thanks,
DP
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.
c Syntax (Toggle Plain Text)
int y=rand(); int num=(y-1)/y;
then you proceed with your next steps...
Thanks,
DP
•
•
•
•
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.
c Syntax (Toggle Plain Text)
int y=rand(); int num=(y-1)/y;
then you proceed with your next steps...
Thanks,
DP
Hey sory i forgot about type casting as i was giving a dummy code.
it should be type cased to float.
Thanks,
DP
c Syntax (Toggle Plain Text)
int y=rand();int num=(y-1)/y;int y=rand(); 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.
•
•
•
•
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
c Syntax (Toggle Plain Text)
int y=rand(); //y should be an integer float num=(float)(y-1)/y; //num should be a float and its typecasted 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.
> 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.
> 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.
•
•
Join Date: Jul 2009
Posts: 4
Reputation:
Solved Threads: 0
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
logically it should be done by a for loop
i tried as follows
but it shows 1 number.
i can't understand my faults
c Syntax (Toggle Plain Text)
#include<stdio.h> #include<stdlib.h> #include<time.h> int random(void) { return(1+rand()%3); } int main(void) { int i; srand(time(0)); for(i=0;i<40;i++); printf("the number is %d\n",random()); }
Last edited by John A; Jul 30th, 2009 at 3:05 pm. Reason: added code tags
•
•
Join Date: Jul 2009
Posts: 4
Reputation:
Solved Threads: 0
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.
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.
![]() |
Similar Threads
- Senior Software Project Manager (Software Development Job Offers)
- Integrate Microsoft Project 2003 in Microsoft SharePoint 2003 Server (Windows NT / 2000 / XP)
- Project on offer - GUI for ATi Drivers (Software Development Job Offers)
- Wade Robson Project (Geeks' Lounge)
- ASP .NET web apps/service in VS.NET won't let me name the project? (ASP.NET)
- amateur coders needed , project in audio streaming (C++)
- Group Project Ideas (Geeks' Lounge)
Other Threads in the C Forum
- Previous Thread: Simple Question regarding char Ptrs
- Next Thread: Start Learning C
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file floatingpointvalidation fork forloop framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux hacking histogram ide include incrementoperators input intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft mqqueue number oddnumber odf opensource openwebfoundation overwrite owf pause pdf performance pointer posix problem probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential single socket socketprogramming standard string systemcall testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






