CS U1 2009 U1 Q4

 

Part A

Identifying and evaluating possible solutions involves generating different approaches to solving the problem.  Solutions will include different methods of solving the problem, e.g contrasting data structures :  one solution may use arrays only, another will use a mixture of arrays and structs.  Each solution is compared against each other to determine individual advantages and disadvantages when compared to each other in terms of efficiency and how well it solves the problem.[1]


[1] https://islandclass.wordpress.com/2020/02/17/stages-in-problem-solving/

Part B

Strategy – keep track of all variables in a trace table, draw output as you go along.

Table – write all variables in the order of its logical use within main control structures, use 1 variable per column:

SIZEj
108
 7
 6
 5
  
  
  

Answer:

----------* 
---------**
--------*-*
-------*--*
------*---*
-----*----*
----*-----*
---*------*
--*-------*
-*--------*
***********

Part C

START
Sum<--0
For i<--14 to 126 DO
	If i%7 ==  0  Then
		Sum<--sum +i
	Endif
Endfor
PRINT Sum
END

Coded solution:

#include <stdio.h>
#include <stdlib.h>

int main()
{
   
    int sum = 0;
    for (int i= 14; i<=126; i++)
        if (i%7==0)
            sum+=i;
    printf("The sum is : %d", sum);

    return 0;
}

© 2021  Vedesh Kungebeharry. All rights reserved. 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s