CSE1111 Mid 241
CSE1111 Mid 241
CSE1111 Mid 241
1. (a) Identify and correct errors in the following code segment (below left).
(b) Find output of the following code segment (below right). [3]
include <stdio> int a=3, b=4, c=-5, result;
Int main { -int mod;
-int Num,a; result = a *b 96c + b;
Num= pri ntf(" result = 96d\n"
, result) ;
- Num+l@ if (result >= @&&result < {
pri ntf ( "0'd Num, a);
return @;
else if (result >= 5) {
96d\n'%b);
else = %d\n" a);
2. (a) Rewrite the code segment (below left) using "if else" without changing the logical meaning.
(b) Manually trace the followingcode segment(belowright) and show all the changes of the
variables i,p, and x inßach step.
3;
return o;
(c) Draw a now chart for the given code segment in Q.2(b) (above right).
Page 1 of 2
to print the following pattern of digit Take n as user input where n is odd
3. (a) Write a C program
and n>=5.
mp n u
Sample output
4. Manually trace the given code segment below. Show the changes of all the variables i, hi, hlw and array (3]
arr elements in each step.
5. Take an array as input of size N. Then take another number as input in K. Your task is to add this
number to the even indexed elements, and subtract from the odd indexed elements.
Sampletlnpu Sample Outpu
14 16 34 36 54
Array Elements: 10 20 30 40 50
OR
Write a program which will take input of N x N numbers in a 2D array A. Now swap all the elements [6]
in the first and last column within the array and finally print the array.
put' m e-båtpu!
3 741
147 382
283 065
560
Page 2 of2