0% found this document useful (0 votes)
19 views2 pages

Mid Term Question 241 CSE1111 E ATR

The document is a mid-term exam paper for the course CSE 1111: Structured Programming Language at United International University. It consists of various programming tasks including error correction, code tracing, flowchart drawing, and pattern printing, with a total of 30 marks. The exam emphasizes the importance of academic integrity, warning against unfair means.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Mid Term Question 241 CSE1111 E ATR

The document is a mid-term exam paper for the course CSE 1111: Structured Programming Language at United International University. It consists of various programming tasks including error correction, code tracing, flowchart drawing, and pattern printing, with a total of 30 marks. The exam emphasizes the importance of academic integrity, warning against unfair means.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

United International University (UIU)

Dept. of Computer Science & Engineering (CSE)


Mid-term Exam: : Trimester: Spring 2024
Course Code: CSE 1111, Course Title: STRUCTURED PROGRAMMING LANGUAGE
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 rules.”

1. (a) Identify and correct errors in the following code segment (below left). [3]

(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 % c + b;
Num = 20%3; printf("result = %d\n",result);
a = Num+10 if (result >= 0 && result < 10) {
printf("%d %f ", Num, a,); printf("a = %d\n", a);
return 0; }
} else if (result >= 5) {
printf("b = %d\n", b);
}
else printf("a = %d\n", a);

C Code for 1(a) C Code for 1(b)

2. (a) Rewrite the code segment (below left) using “if … else” without changing the logical meaning. [3]

(b) Manually trace the following code segment (below right) and show all the changes of the [3]
variables i,p, and x in each step.

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


switch(num) { int main() {
case 1: sum *= 3; int p=1;
case 2: int x = 490;
case 3: sum += --j * 2; for(int i=1;i<=p;){
i--; break; printf("%d %d %d\n",i,p,x);
case 4: sum = ++i * j--; if(x % 29 == 0){
break; printf("Not a great number!");
case 5: break; break;
i += 10; }
default: sum *= i++ / j--; else {
i=i % j; break; x -= 13;
} p += x % 10;
i += 3;
}
}
return 0;
}
C Code for 2(a) C Code for 2(b)

(c) Draw a flow chart for the given code segment in Q.2(b) (above right). [3]

Page 1 of 2
3. (a) Write a C program to print the following pattern of digit ‘2’. Take n as user input where n is odd [3]
and n>=5.
Sample input n=5

Sample output *****


*
*****
*
*****

(b) Replace the “outer” while loop with “for” and the “nested” for loop with “while” loop in the [3]
following code without changing the logical meaning of the program.
int i=0, count = 0;
int n = 12345;
while (n != 0) {
printf ("%d", n % 10);
count++;
for(; i<count; i++) {
printf("%d", n/= 10);
}
printf ("\n");
}
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 = 0, hlw = 10;


int arr[4] = {10, 20, 30, 40};
for(int i=4; i<=hlw; i++) {
arr[hi] = arr[hi+1] - 5;
hlw -= 2;
}
5. Take an array as input of size N. Then take another number as input in K. Your task is to add this [6]
number to the even indexed elements, and subtract from the odd indexed elements.

Sample Input Sample Output


N=5 14 16 34 36 54
Array Elements: 10 20 30 40 50
K=4
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.

Sample Input Sample Output


3 741
147 382
283 065
560

Page 2 of 2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy