Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise 1: (i) Describe the following three programming constructs with a suita

ID: 3724593 • Letter: E

Question

Exercise 1: (i) Describe the following three programming constructs with a suitable problem statement for each. You must write the code as well. Not required to code in Java and paste it, you can type it sing MS- Word (a) Sequence (b) Selection (c) lteration/Repetition (30 points) (ii) Describe the Relational operators you are familiar with and their usage as well. (ii) Describe the three logical operators and explain their usage (iv) Describe the difference between a local variable and a global variable. (v) Describe one difference between the While loop and the do while loop. (10 points) (10 points) (5 points) (5 points)

Explanation / Answer

i)
a)SEQUENCE:

Sequnce is the one of the basic logic structure,In a sequence structure an action or eventleads to the next ordered action in a predetermined order.
If the instruction in sequence logic structure the instructions execute step by step instructions but no instructions can be skipped in the sequence.

Selection:

It is the one of the structure of c programming based on the selection the instructions are executed.In this selection we can check the condition if the condition is true than only execute the next instruction otherwise control go to the another branch.

for example:if(a<3)

{printf("a value is less than 3");}

else{

printf("a value is greater than 3");}

Iteration:

If we can execute the block of instruction in number of times we can use iteration.

Iteration is also called as looping.In that we can initialise the loop control variable.

Decision making is used to performing whether the further loop is necessary or not.

If the condition is true than execute the statements and increment/decrement the loop control variable.

If the condition is false loop control go to the end of the loop.

example:for,while, dowhile are the iterations

ii)Relational operators:

They are 6 relational operators

One of the operators are less than <,greater than >

using relational operator in comparisions of conditions.If the comparision is true then do some specific work otherwise can do some other work.

for example:a=3

a<6 is true

a<2 is false

a>1 is true

a>10 is false

iii)LOGICAL OPERATORS:

Three logical operators are

logical AND &&

logical OR ||

logical NOT !

The logical && and || operators are used to test more than one condition and take the decision

example:a=2,b=12

a<12 && x==10 if 2 condition are true than only true

truth table for logical operators:

a b a&&b a b a||b a !a

0 0 0 0 0 0 0 1

0 1 0 0 1 1 1 0

1 0 0 1 0 1

1 1 1 1 1 1

iv)The main difference between the local variable and golbal variable is scope.

if the variable is local variable that variable can access with in the function block only we cannot use the variable in out of the function block.

If the variable is defined in global variable we can access the variable in the entire the program.

v)While Loop:

While is a keyword.It is a entry controlled loop structure.

Because it check the condition at the begining of the loop.If the condition is true then loop is repeated.

If the condition is false then loop is not executed.

Do-While:

It contains 2 keywords like do and while

This is exist controlled loop structure.

Before checking the condition the statements executed atleast once.

if the condition is true then statements inside the block is executed.

If the condition is false then statements inside the block not executed.

In do-while loop cheak the condition at the end of the loop.

The main difference is in while check condition first and execute the block of code wnen condition is true only,In do-while the block of code is executed once and then check the condition.