# i'm stumped on a quiz that i'm taking

Discussion in 'OT Technology' started by Oddo, Apr 17, 2007.

Not open for further replies.
1. ### OddoAnd then Trogdor smote to Kerrek and all was laid

Joined:
Oct 21, 2002
Messages:
571
0
Location:
houston
could anyone guide me in the right direction on either of these two questions?

1.

Read a positive integer value, and compute the following sequence: If the number is even, halve it; if it's odd, multiply by 3 and add 1. Repeat this process until the value is 1, printing out each value. Finally print out how many of these operations you performed.
Typical output might be:
Initial value is 9 Next value is 28 Next value is 14 Next value is 7 Next value is 22 Next value is 11 Next value is 34 Next value is 17 Next value is 52 Next value is 26 Next value is 13 Next value is 40 Next value is 20 Next value is 10 Next value is 5 Next value is 16 Next value is 8 Next value is 4 Next value is 2 Final value 1, number of steps 19

***I don't know how to count the steps.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.

Write a simple menu driven calculator program that performs complex number arithmetic. In this exercise, user will interactively input two complex numbers X and Y from the terminal, and store them to two arrays; both arrays have the same size 2 (real and imaginary).

For example, if the complex number is 4.5+3i, then it will be stored to an array as: X[2]={4.5, 3};

Your program will have the ability to calculate the addition, subtraction of the two complex numbers, and modulus (magnitude) of elements of the complex number. You are asked to write a function modulus(), which has one input parameter the complex number. Ask the user to choose one of the options (1, 2, 3). Based on the user’s input, your program will print out proper result.

2. Subtract
3. Modulus

2. ### OddoAnd then Trogdor smote to Kerrek and all was laid

Joined:
Oct 21, 2002
Messages:
571
0
Location:
houston
its a C quiz by the way

3. ### Create:free at last:

Joined:
Jan 4, 2006
Messages:
8,043
2
For number one, just create an int variable, set it to zero, then variable++ each time your computation/output loop iterates. Once the loop completes, simply output the variable's value.

The second problem is cake, so long as you understand the math.

What are you studying? Arrays? Pointers? Loops? What tools are we allowed to use?

4. ### deusexaetheraOT Supporter

Joined:
Jan 27, 2005
Messages:
19,712
0

Has it occurred to you, if you get an answer to a question as simple as this one from people who might very well be doing this for a living, that it might be glaringly obvious to your professor that you cheated? This is pretty obviously a take-home quiz, so grab your textbook and do it your own goddamned self.

Joined:
Apr 10, 2004
Messages:
4,608
0
Location:
Melbourne
The first one is stupidly easy. Could be done with 1 for loop with 2 if's inside. Add in a couple of printf's, voila. It literally may be a 10 line program.

However, if I remember correctly that number sequence doesn't necessarily end so be careful of the starting number that you choose.

2 is really just understanding the math part of it. Will be a bit longer than the first program, but it isn't difficult.

6. ### Create:free at last:

Joined:
Jan 4, 2006
Messages:
8,043
2
I think the best hint we could give without doing the work is: "Look at 'if-then' statements, then at 'while-do' and 'repeat-until' loops"

If you're still lost, you need a TA/tutor.

Joined:
Jun 6, 2006
Messages:
32,407