CSE1111 Mid 241

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

United InternationalUniversity (UIU)

Dept. of Computer Science & Engineering (CSE)


Mid-term Exam: : Trimester: Spring 2024

Time: 1 hour 30 min Total Marks: 30


Answer all the questions.
"Any examinee found adopting unfair means will be expelled from the trimester / program as per
UIU disciplinary ruley."

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.

int num=5,sum=l@,i=4, j=9; #include <stdio.h>


swi tch(num) { int main() {
case 1: sum 3; int p=l;
case 2: int x = 49@;
case 3: sum += --j * 2 for (int
break; printf("96d 96d , i , p, x);
case 4: sum= ++i * j- if (x % 29 —
break; printfC'Not a great number!'I) •
case 5: break; break;
default: sum i ++ / j- else
96j; break; = 13;

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

for loop with "while" loop in the


(b) Replace the "outer" while loop with "for" and the "nested"
following code without changing the logical meaning of the program.
int count = 0
-
int n 12345;
white (n != 0) {
printf ("96d"
count++•,
for(; i<count; i ++) {
pri 10);
printf

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.

int hi = @, hlw = 10;


int arr[4] = {10, 20, 30, 4@}•,
for (int i=4; i++) {
arr[hi] = arr[hi+l]
hlw -z 2;

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

You might also like