The output is:
1 10 5 6
Here is the reason why.
dostuff is passed three values: 1, 10, and 5. 1 goes into its parameter n, 10 goes into its parameter o, and 5 goes into its parameter m. dostuff prints these values and computes its return value of 1 + 10 - 5, which is 6. That's returned to the main program, which stores it in p and then prints p.
The output is:
Hello 2 Hello 4 Goodbye 8 Goodbye 16
Here's the reason why.
n is set to 1 before the loop. The loop then tests whether n is less than 16, which it is, so we go through the loop. This involves multiplying n by 2, which sets it to 2. We then test whether that's less than 8, which it is, so we write the Hello and n's'value (2).
We now do the test again (which verifies that n is less than 16), so we go through the loop again, which multiplies n by 2, setting it to 4, which is still less than 8, so we write Hello and 4.
We do the test again, which is true again (since n is 4, which is less than 16), so we multiply n, which sets it to 2, giving us 8. Now the if will do the else part, printing Goodbye and 8.
Once again, we do the loop test, which is still true, so we multiply n by 2 again, which sets it to 16. Now the if does the else again, printing Goodbye and 16.
Now we do the loop test, but n is 16, which causes the loop to terminate.
The output is:
5 3 1
Here is the reason why.
i starts out with 5. We do the test of the loop, which checks whether i is non-negative, which it is, and then do the body of the loop, the printf, which writes i's value (5). We then subtract 2 from i, which sets i to 3.
We do the test again, and then the body of the loop, which prints i's value (3), and subtract 2 from i, setting it to 1.
We then do the test again, then execute the body of the loop, printing i(1), and the subtraction, which sets i to -1.
Now when we do the test, it's no longer true that i is non-negative, so we terminate the loop.
The output is:
13,4,5,15
m's value is computed by taking 2 times 3 (6) adding that to 5 (giving 11) and then adding 2 to it, which gives us 13. Remember, C multiplies and divides before doing addition and subtraction).
n's value is set to the result of computing 5 times 2 (which is 10) minus the result of computing 3 times 2 (which is 6).
q's value is set to 5.
p's value is the result of q plus 10, which is 15.
The changes are:
The changes are:
The changes are:
One possible solution is:
#includemain() { int count_a; int count_all; int score; count_a = count_all = 0; while (scanf("%i", &score) == 1) { count_all = count_all + 1; if (score >= 90) count_a = count_a + 1; } percent_a = (count_a * 100) / count_all; printf("%i%% of the students (%i out of %i) got A's", (count_a * 100) / count_all, count_a, count_all); }
The key to this solution is using the function, drawFilledBox, that you are allowed to assume already exists. Because that function does the hard work, all you have to do is repeatedly call it, passing it the desired height and width of each box you want to write.
void drawBoxes(int m)
{
void drawFilledBox(int h, int w);
int i;
for (i = 1; i <= m; i++)
{
drawFilledBox(i, i);
printf("\n");
}
}
[EE150 Home Page | E150 Exam Information Page | Top Of Page]