Please support our C advertiser: Programming Forums
Views: 6517 | Replies: 17 | Solved
![]() |
OK, I'm being silly, this is the correct version of the code that compiles and runs.
Thanks very much vijayan! Now when it runs I get 176 numbers printed out in sequence... How can I get more control over how many it prints out, because I'll be wanting to do up to 10,000, and possibly more? Is it by playing around with line 12?
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> int i; void generate_ascending_number(int n) { int available = RAND_MAX; int required = n; for (i=0; i<available; ++i) { if ( (rand() % (available-i)) < required) { printf("%d\t", i); } } } int main() { generate_ascending_number(20); return 0; }
Thanks very much vijayan! Now when it runs I get 176 numbers printed out in sequence... How can I get more control over how many it prints out, because I'll be wanting to do up to 10,000, and possibly more? Is it by playing around with line 12?
Never approach a computer with the words "I'll just do this quickly..."
Hmmm. I've put 1024 in there, and it sure prints out a lot of numbers, which might well be 1024 numbers. But when I put in 10, it prints out 98 numbers, and when I put in 5, it prints out 50 numbers. I've tried this more than once now... any ideas why this is happening please?
Never approach a computer with the words "I'll just do this quickly..."
Yea you're right, now it works. Thanks so much, you've been amazing. But may I please ask a couple more things: "--required" decrements that variable so that the number entered into the function is the number of numbers printed out right?
And how can I adjust the range pls?I tried putting a variable with a smaller number in the place of 'available' in line 13 & it compiled, but when i ran the program I got an 'Arithmetic Exception'. Sorry to keep hassling like this.
And how can I adjust the range pls?I tried putting a variable with a smaller number in the place of 'available' in line 13 & it compiled, but when i ran the program I got an 'Arithmetic Exception'. Sorry to keep hassling like this.
Never approach a computer with the words "I'll just do this quickly..."
Again, apologies, so embarassing, I solved the 2nd qstn, I have to use the same value in lines 11 & 13 if I'm going to use something different from 'available'.
Thanks v much for all your help vijayan, it's very much appreciated!
Thanks v much for all your help vijayan, it's very much appreciated!
Last edited by Thinka : Apr 29th, 2007 at 1:56 pm.
Never approach a computer with the words "I'll just do this quickly..."
•
•
Join Date: Dec 2006
Location: india
Posts: 1,087
Reputation:
Rep Power: 9
Solved Threads: 163
see thread at
http://www.daniweb.com/techtalkforum...tml#post345699
this fills an array, instead of printing out the random number; but the idea is the same
http://www.daniweb.com/techtalkforum...tml#post345699
this fills an array, instead of printing out the random number; but the idea is the same
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode