Question: 1. Topics: Program Control, Recursion, Pseudocode a) Convert the following while loop into_a_ for loop. #include int main() { int sum = 0, i =
1. Topics: Program Control, Recursion, Pseudocode
a) Convert the following while loop into_a_ for loop. #include int main() { int sum = 0, i = 3; while (i b) i) What reserved word can be used to_end_an execution of a loop? ii) A sequence of six tests, all scored out of 100, are to be given different weightings in determining a final mark. The following incomplete C program should compute the appropriate weighted score for one test. The fragment should first read values of testNumber and score. Complete the program below by using switch statement, to compute and print the appropriate value of weightedScore using the weightings given in the following table.
| Test Number | Weight |
| 1 | 10% |
| 2 | 20% |
| 3 | 20% |
| 4 | 15% |
| 5 | 15% |
| 6 | 20% |
For example, input of 3 and 27 should produce the following output: A score of 27 on test 3 gives a weighted score of 5.40.
#include int main() { int testNumber, score; float weight = 0.0; printf("Please enter the test number and the score: "); scanf("%d%d", & testNumber, & score); //complete your switch statement here printf("A score of %d on test %d give a weighted score of % .2 f ", score, testNumber, weight); return 0; } iii) Write a function that solves the same problem described in part ii) using only conditional expressions. The whole body of the function should be written using only one statement. The following C program will display the following output for an input of 3 and 27: A score of 27 on test 3 gives a weighted score of 5.4.
#include float result(int testNumber, int score); //function prototype int main() { int testNumber, score; float weight = 0.0; printf("Please enter the test number and the score: "); scanf("%d%d", & testNumber, & score); weight = result(testNumber, score); printf("A score of %d on test %d give a weighted score of %.2f ", score, testNumber, weight); return 0; } float result(int testNumber, int score) { //write your function }
c) Based on the following program with TWO functions:
1: #include
What is the output if n = 3 in line 9?
d) Translate the following flowchart to pseudocode.

2. Topics: Pointers, Linked-List, Scope, C-Function a) The following C program compiles, links without errors and should print CMP10, but it produces segmentation faults when we run it.
1: #include
46: 47: // add x to front of strlist and return pointer to new list head 48: Node *push_node(Node x, Node *strlist) { 49: x.next= strlist; 50: return &x; 51: }
Identify the TWO errors in the code and suggest minimal changes that would allow the program to execute successfully. Your changes should not alter the general structure of the program, i.e., it should still link the two nodes in the main program into a linked list and print it. Indicate the line of code of each error, describe the error and give the correct code. b) What does the following function do? int mysteryFunction(char *x){ char *marker; int count = 0; for(marker = x; *marker; ++marker) ++ count; return count; }
c) Based on the following program:
#include i) Identify the local variables ii) Identify the global variables iii) Identify the formal parameters iv) Identify the actual parameters v) What is the output of the above program?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
