[go: up one dir, main page]

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

Spring 2024 CSE 1111 Final Exam

Uploaded by

Mahim Sawon
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)
36 views2 pages

Spring 2024 CSE 1111 Final Exam

Uploaded by

Mahim Sawon
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)


Final Exam:: Trimester: Spring 2024
Course Code: CSE 1111, Course Title: Structured Programming Language
Total Marks: 40 Duration: 2 hours
[Any examinee found adopting unfair means will be expelled from
the trimester/program as per UIU disciplinary rules.]
There are FIVE questions. Answer all the questions. Marks are indicated in the right margin.
Q.1 a) Write a C program according to the following: [4]
i. Write a function int factorial(int n) that will return the factorial of a given number. Factorial of a
number can be calculated by multiplying the numbers from 1 to n consecutively. For example,
factorial of 4 = 1×2×3×4 = 24. Assume n will not be greater than 10.
ii. Write a function int sum(int a, int b) that will return the sum of two given numbers.
iii. In the main function, take three integers as inputs and calculate the sum of the factorial of those
integers using the above functions factorial() and sum(). Note that you cannot make any
modifications to the previously defined functions.
b) Find the output of the following program (left). Notice the local and global contexts. [4]

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


int x = 2, y = 3; #include <string.h>
int fun1(int n){
return n%11; int main() {
} char A[101] = {'\0'};
void fun2(int arr[], int n){ char B[101] = "string";
for(int i = 0; i<n; i++){
x = fun1(x) + fun1(y); strncpy(A, B, 4);
arr[i] = arr[i] + x; strncat(A, "kernel", 3);
y = fun1(y) + fun1(x);
} for(int i=0; B[i]!='\0'; i++) {
} if(B[i]=='i') {
int main(){ B[i] = '\0';
int a[] = {2, 3, 5, 7, 11}; }
fun2(a, 5); }
for(int i = 0; i<5; i++) printf("%s - %s\n", A, B);
printf("%d ", a[i]); return 0;
} }
C Code for 1(b) C Code for 2(a)
Q.2 a) Show manual tracing (every change) of variables i, A, and B of the program above at right. [4]
b) Consider the following string declaration: [4]
Char str[55]=“I love spl. Uiu has some good labs for spl.”;
Write a C program that will replace each occurrence of the word "spl" with "dsa" and print out the
resulting text. You cannot use any library functions.

Q.3 a) Identify and correct the errors of the following code: [3]
struct student{
char name[];
int ID;
}
int main() {
student s1,s2;
s1.name="Rahim";
s1.ID=101;
struct student* s_ptr = s2;
scanf("%s",&s_ptr.name);
scanf("%d",&s_ptr.ID);
}

Page 1 of 2
Q.3 b) Write a C program to store the following information about patients and perform the following [5]
operations:
i. Create a structure named Patient with the following members: name (string), age (int),
height (float), weight (float) and BMI (float).
ii. Declare an array of size 100 of type Patient structures.
iii. Take inputs (name, age, height, weight) from the keyboard and calculate the BMI of the
respective patient using the formula: weight / (height).
iv. Find and display all the information of the youngest patient with lowest age.
Q.4 a) Write the output of the program provided below on the left. [4]
b) Find the output of the code provided below on the right. [4]

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


int power_of_2(int n) { void inc(int *ap, int dummy){
printf("Inside power_of_2(%d)\n", n); for(int i=0; i<dummy; i++){
if(n == 1) return 1; *ap = *ap + 1;
if(n % 2 != 0) return 0; ap = ap + 2;
return power_of_2(n / 2); }
} dummy = 100;
int main(void){ }
int num = 16; int main() {
power_of_2(num); int a[] = {1,2,3,4,5,6,7,8};
return 0; int dummy = 3;
} inc(&a[2], dummy);
C Code for 4(a) for(int i=0; i<8; i++)
printf("%d ",a[i]);
printf("\nDummy=%d\n", dummy);
return 0;
}
C Code for 4(b)

Q.5 a) Write a C program that does the following: [4]


 Declare an integer array arr with array size 100.
 Declare a pointer variable arrPtr and assign the array arr to it.
 Scan the elements of the array arr using the pointer arrPtr with offset.
 Find and print the largest element of arr using the pointer arrPtr.

b) Suppose, you are trying to save a simple string in a file named “string.txt”, and for this you have
written the following code:
FILE *fp = fopen("string.txt", "w");
fprintf(fp, "Yet another string\n");
fclose(fp);
i. What will happen if the file does not exist? [1]
ii. What is the difference between read and append mode? [1]
iii. Write C code segment to re-open the same file in append mode and add a new string “This
[2]
is another string” into the file and then close the file.

Page 2 of 2

You might also like