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

UCTC CSE-211 Exam Paper 2024

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)
62 views2 pages

UCTC CSE-211 Exam Paper 2024

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

R1

University of Creative Technology, Chittagong (UCTC)


Department of Electrical & Electronic Engineering
B. Sc. Engineering Examination, Spring (Final)-2024
3rd Semester
Course Title: Computer Programming
Course Code: CSE-211

Time: 120 minutes Total Marks: 40

Instructions for the students: Answer any four from the following questions. All the questions contain
equal marks. Assume reasonable data if any missing. Necessary charts may be supplied on request.
Only use of calculator is allowed for the purpose of calculation. Use of any electronic devices is strictly
prohibited in the exam hall.

1. a. #include <stdio.h> 2
int main()
{
int a[2][2] = { 10, 20, 30, 40 };
int *p;
p = &a[1][0];
return 0;
}
Find the value of *p, *(p+1),*p-1,*(p-2)
b. Write a program in C to separate odd and even integers into separate arrays and display 4
them.
c. Write a program in C to sort elements of an array in ascending and descending order. 4

2. a. What will be the output of the following C code? 2


#include<stdio.h>
int main() {
int n,i;
n=f(6);
printf("%d",n);
}
f(int x) {
if(x==2)
return 2;
else {
printf("+");
f(x-1);
}
}
b. Write a program in C to get the largest element of an array using the function. 4
c. Write a C program to find factorial of any number using recursion 4
3. a. Write a program in C to compute the sum of all elements in an array using pointers. 5

b. What will be the output from the following program? 5


#include<stdio.h>
int main() {
int a[] = { 2, 6, 10, 14, 18} ;
int *ptr1, **ptr2, *ptr3;
ptr1 = a;
ptr2 = &ptr1;
ptr3 = a+2;
printf(" %d \n", *(ptr1 + 1));
printf(" %d \n", *ptr1 + 1);
printf(" %d \n", *(*ptr2+ 2));
printf(" %d \n", **ptr2 + 2);
printf(" %d \n", *ptr3 + 2);
return 0;
}

4. a. Write a program to enter the marks of 5 students in English, Mathematics and Biology 5
using a structure named Result having elements student_name, ID, eng_marks,
math_marks and bio_marks and then display the average marks of each student.
b. Write a C program to store the employee information (ID, Name, Joining date, Salary) 5
using structure. Declare a nested structure to store the joining date which includes day,
month and year.

5. a. Following file contains name and ID of 5 students: 5

[Link]
Himel 1001
Joy 1002
Shihab 1003
Riya 1004
Samiha 1005

Write a C program to perform write operation on the file [Link] and store the
file contents mentioned above in it.
b. Write a C program that creates a new file by deleting all the vowels(a,e,i,o u) from 5
an existing file.

Common questions

Powered by AI

Nested structures in C are used to encapsulate complex data types within a single entity, enhancing organization and readability. When storing date information, nested structures provide a clear and hierarchical method to manage date-related data as a part of larger structures. For example, a structure for employee data including a nested structure for the joining date (with elements like day, month, and year) enables structured manipulation of the full employee record while keeping related information tidy and easily accessible. This practice reduces complexity, especially in programs handling multiple interconnected data items .

Recursion in C programming involves a function calling itself to solve smaller instances of the problem. In calculating factorial using recursion, the base case is when the number is 0 or 1, in which case the factorial is 1. The recursive case involves the function calling itself with the reduced number until it reaches 1. This is defined in the function as: if the input number n is greater than 1, the function returns n multiplied by the factorial of (n-1). This process of dividing the problem into simpler sub-problems continues until the base case is reached .

In the given C code, the outputs of the pointer operations demonstrate how pointers enable memory access and manipulation. For the array int a[] = { 2, 6, 10, 14, 18}, the results are as follows: *(ptr1 + 1) equals 6 (accessing the second element), *ptr1 + 1 equals 3 (adding 1 to the value pointed by ptr1, which is 2), *(*ptr2+ 2) equals 10 (accessing the third element via the double pointer), **ptr2 + 2 equals 4 (adding 2 to the value pointed by ptr1), and *ptr3 + 2 equals 12 (adding 2 to the value at the third element, which is 10). These outputs underscore pointers' role in efficiently traversing and modifying array data through address arithmetic .

Using a structure in C to manage student data provides an organized and efficient way to handle complex data types. A structure allows grouping of variables of different types under a single name, thus facilitating manipulation, storage, and retrieval of data in a coherent manner. For instance, by creating a structure named Result that includes elements such as student_name, ID, eng_marks, math_marks, and bio_marks, the program can easily manage and process each student's data collectively. This approach reduces errors and improves readability, as related data is accessed and manipulated as a single unit rather than discrete elements .

To modify a file by removing specific characters like vowels in C, the program should open the file in read mode, read the contents, remove the vowels ('a', 'e', 'i', 'o', 'u'), and write the modified content to a new file. This can be accomplished by checking each character as it is read and excluding vowels from the output. A major challenge might be handling large files efficiently, ensuring memory management, and maintaining data integrity during the read and write operations. Ensuring that file pointers and buffer management are correctly implemented is crucial to prevent data loss and corruption .

Using functions to find the largest element of an array in C enhances code modularity and reuse by breaking down tasks into smaller, manageable units that perform specific actions. A function dedicated to finding the maximum element can be easily reused across different programs or modules without having to rewrite the logic. This reduces code redundancy, improves readability, and facilitates debugging. Functions make programs easier to maintain and expand, as changes can be made in a single place and be reflected wherever the function is used .

To calculate the average of student marks stored in a structure in C, the program should iterate over the structure containing student records, extract marks for each subject, and compute the average. This involves defining a structure with fields for storing student info like name, ID, and marks, then iterating through each student record to sum up the marks for subjects like English, Mathematics, and Biology, and dividing by the number of subjects to get the average. Displaying this average requires reading data from each structured student entry and performing the arithmetic operation outside the loop to ensure accuracy .

In C, pointer arithmetic depends on the type size of the elements the pointer points to. In the case of a two-dimensional array, like int a[2][2], when you declare a pointer and point it to a specific element, you are dealing with the memory address of that element. The declaration int *p; p = &a[1][0]; sets p to refer to the memory address of the element a[1][0] (which is 30). The expression *p returns the value at this address (30), and pointer arithmetic allows moving between adjacent memory locations that hold similar types of data. *(p+1) would move the pointer to a[1][1] (40), so *(*p+1) gives 40. Conversely, *(p-1) refers to a[0][1] (20), and *(p-2) refers to a[0][0] (10).

Key considerations when performing file write operations in C for managing student records include ensuring correct file opening modes, proper data formatting, error handling, and data validation. It is important to open files in write mode adequately to prevent data loss, format the data correctly to preserve the meaning and readability of records, and implement error-checking routines to handle unexpected situations like disk failure or wrong path. Data validation ensures only accurate data is written to the file. These considerations are critical to maintain data integrity, prevent corruption, and ensure reliable retrieval and manipulation of student records for future use .

A C program can separate odd and even integers into different arrays by iterating through the original array and applying the modulus operator to determine if each integer is odd or even. When an integer is even, it is placed into an even array, whereas an odd integer goes into an odd array. This operation is commonly used in algorithms and data analysis to organize and process data based on parity, facilitating operations that require segmentation of data into odd and even groups to perform specific calculations or logic .

You might also like