|
|
Austin10831 Posts
|
algorithm 1 prints all the positive integers less than or equal to the input, then print the input itself (cus of the "Print Count" after the while loop) ,so if you input 3, you get 1 2 3 3. If you input -1, you get -1
|
51281 Posts
On June 01 2008 19:24 imDerek wrote: algorithm 1 prints all the positive integers less than or equal to the input, then print the input itself (cus of the "Print Count" after the while loop) ,so if you input 3, you get 1 2 3 3. If you input -1, you get -1
if you inputted -1 wouldn't it be just a print count of 0 because if the count is set to 0, the loop is skipped since your number is -1?
|
Insead of dumping your entire homework into your blog, why don't you just specifically tell us what you are having trouble with. And like you pointed out, input of -1 gives output of 0, because that is what the count variable was initiated as and it hasnt been changed.
|
Zurich15306 Posts
3) i = 1 while i < 42 print i increment i by 2
|
Sydney2287 Posts
Us telling you the output isn't gonna help you out much.
My suggestion if you are having trouble is to do a desk check, i.e. go through the algorithm step by step and write down the variables and their values at each point, and any output the algorithm generates.
|
On June 01 2008 19:44 GTR-2-Go wrote:Show nested quote +On June 01 2008 19:24 imDerek wrote: algorithm 1 prints all the positive integers less than or equal to the input, then print the input itself (cus of the "Print Count" after the while loop) ,so if you input 3, you get 1 2 3 3. If you input -1, you get -1 if you inputted -1 wouldn't it be just a print count of 0 because if the count is set to 0, the loop is skipped since your number is -1?
right, sorry bout that
|
For number 3, in scheme:
STk> (define (waa) (define (wee x) (if (= x 20) nil (cons (+ 1 (* 2 x)) (wee (+ x 1))))) (wee 0)) waa
STk> (waa) (1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39)
I'll explain: (waa) is a loop, it basically runs another recursive function w/ input of 1, this function is called wee
How wee work: wee is a function that takes input, that are actually indexes of the odd number, 1 would be indexed 0, 3 is 1, 5 is 2 on the index, and so on...
if input=20, gives nothing, so it terminates. if input<20, add to the front of the array (2*input + 1), the corresponding odd number to the index, and recursively construct the rest of the array with input+1, the next index.
I dunno if its clear ~~
|
51281 Posts
Alright, did this finally, just used some help from a programming friend (hi stenole).
Thanks for the help.
|
On June 01 2008 20:33 evanthebouncy! wrote: I'll explain: (waa) is a loop, it basically runs another recursive function w/ input of 1, this function is called wee
If we ever worked on a programming project together, I would probably have to kill you. wee and waa are not good names for things unless you are trying to make code unreadable on purpose.
|
Wow, I just can't read without () and {} ...
|
<br>hi</br>
coding pro right here
|
United States24494 Posts
void isgtrgay() { char gtrgay='y'; while (gtrgay=='y') { cout << "GTR is gay for that match last night!\n"; } return; }
|
On June 02 2008 00:08 boss420 wrote: <br>hi</br>
coding pro right here You can't close a break tag like that... its a singular tag, it doesn't enclose anything (and the proper way to do it would be <br /> )
|
On June 01 2008 21:10 stenole wrote:Show nested quote +On June 01 2008 20:33 evanthebouncy! wrote: I'll explain: (waa) is a loop, it basically runs another recursive function w/ input of 1, this function is called wee
If we ever worked on a programming project together, I would probably have to kill you. wee and waa are not good names for things unless you are trying to make code unreadable on purpose. chill :p I'm more of a mathmatics major
|
|
|
|