BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) Question Paper 2076 Nepal
This is the official BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) question paper for 2076, as set in the regular annual examination. It carries 80 full marks and a time allowance of 180 minutes, across 11 questions. On Kekkei you can attempt this Computer Programming in C (IOE, CT 401) past paper online with a timer, get instant AI feedback and step-by-step solutions, and track the topics where you lose marks — completely free. Whether you are revising for your BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) exam or solving previous years' question papers, this 2076 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt all questions.
Define the four basic data types in C and state the typical storage size (in bytes) and the value range for each on a 32-bit compiler. Distinguish between automatic type conversion (implicit) and type casting (explicit) with a short example of each. Then evaluate the following C expression manually, showing every intermediate step and the final data type and value:
int a = 17, b = 5;
float r;
r = a / b + (float)a / b + a % b;
Four basic (primitive) data types in C (32-bit compiler):
| Type | Size (bytes) | Typical Range |
|---|---|---|
char | 1 | to (signed) |
int | 4 | to |
float | 4 | (6-7 significant digits) |
double | 8 | (15-16 significant digits) |
Implicit conversion (type promotion): The compiler automatically converts a lower-rank type to a higher-rank type in a mixed expression. Example:
int n = 3; float f = n + 2.5; // n promoted to float -> f = 5.5
Explicit conversion (type casting): The programmer forces a conversion using the cast operator (type). Example:
int total = 7, count = 2; float avg = (float)total / count; // avg = 3.5
Step-by-step evaluation of the expression with a = 17, b = 5:
a / b-> integer division: (fractional part truncated). Type:int, value .(float)a / b->acast to17.0, then17.0 / 5promotesbto float: . Type:float, value .a % b-> modulus (remainder): . Type:int, value .- Sum: . The
intoperands are promoted tofloat: . - Assigned to
float r, so no truncation occurs.
Final result: r = 8.4 (type float).
Explain the difference between call by value and call by reference in C. Write a C program using a user-defined function to compute the factored design load on a beam given dead load and live load using the load combination (in kN). The function must return the factored load. Demonstrate, with a dry run, the output of your program for and .
Call by value vs call by reference:
- Call by value: A copy of the actual argument is passed to the function. Changes made to the parameter inside the function do not affect the original variable. Used when the caller's data must be protected.
- Call by reference: The address of the actual argument is passed (via pointers). The function can modify the original variable directly. Used to return multiple values or modify caller data.
C program (call by value, returning the factored load):
#include <stdio.h>
float factoredLoad(float D, float L) {
return 1.2f * D + 1.6f * L; // ACI/IS load combination
}
int main(void) {
float dead = 25.0f, live = 40.0f;
float W = factoredLoad(dead, live);
printf("Factored design load W = %.2f kN\n", W);
return 0;
}
Dry run for , :
factoredLoad(25.0, 40.0)is called;D = 25.0,L = 40.0(copies).- .
- .
- Return .
Program output:
Factored design load W = 94.00 kN
Final factored design load: .
A civil engineer records the compressive strength (in MPa) of 6 concrete cube samples in a 1-D array: {28.5, 31.0, 27.2, 33.4, 29.8, 30.1}. Write a complete C program that uses arrays and loops to: (a) compute and print the average strength, (b) find and print the maximum strength, and (c) count how many samples meet the design requirement of at least 30 MPa. Then compute each of these three results by hand to verify the program output.
C program:
#include <stdio.h>
int main(void) {
float s[6] = {28.5f, 31.0f, 27.2f, 33.4f, 29.8f, 30.1f};
float sum = 0.0f, max = s[0], avg;
int i, count = 0;
for (i = 0; i < 6; i++) {
sum += s[i];
if (s[i] > max) max = s[i];
if (s[i] >= 30.0f) count++;
}
avg = sum / 6;
printf("Average strength = %.2f MPa\n", avg);
printf("Maximum strength = %.2f MPa\n", max);
printf("Samples >= 30 MPa = %d\n", count);
return 0;
}
Hand verification:
(a) Sum MPa. Average MPa.
(b) Comparing values, the largest is MPa.
(c) Samples : , , -> 3 samples. (Note is excluded.)
Program output:
Average strength = 30.00 MPa
Maximum strength = 33.40 MPa
Samples >= 30 MPa = 3
Final answers: average MPa, maximum MPa, count .
Define a structure named Survey to store the data of a survey station: a station name (string), and its coordinates x, y, z (all float, in metres). Write a C program that (a) reads data for 3 stations into an array of structures, (b) writes the records to a text file stations.txt, and (c) reads the file back and prints each record. Explain the role of fopen, fprintf, fscanf, and fclose in your program.
Structure definition and program:
#include <stdio.h>
struct Survey {
char name[20];
float x, y, z; // metres
};
int main(void) {
struct Survey st[3];
int i;
FILE *fp;
/* (a) read input */
for (i = 0; i < 3; i++) {
printf("Enter name x y z for station %d: ", i + 1);
scanf("%s %f %f %f", st[i].name, &st[i].x, &st[i].y, &st[i].z);
}
/* (b) write to file */
fp = fopen("stations.txt", "w");
if (fp == NULL) { printf("File error\n"); return 1; }
for (i = 0; i < 3; i++)
fprintf(fp, "%s %.2f %.2f %.2f\n", st[i].name, st[i].x, st[i].y, st[i].z);
fclose(fp);
/* (c) read back and print */
struct Survey r;
fp = fopen("stations.txt", "r");
if (fp == NULL) { printf("File error\n"); return 1; }
printf("\nStation records:\n");
while (fscanf(fp, "%s %f %f %f", r.name, &r.x, &r.y, &r.z) == 4)
printf("%s (%.2f, %.2f, %.2f)\n", r.name, r.x, r.y, r.z);
fclose(fp);
return 0;
}
Role of file functions:
fopen(name, mode)opens the file and returns aFILE*pointer; mode"w"creates/overwrites for writing,"r"opens for reading. ReturnsNULLon failure.fprintf(fp, ...)writes formatted data to the file (likeprintfbut to a stream).fscanf(fp, ...)reads formatted data from the file (likescanfbut from a stream); returns the count of items successfully read.fclose(fp)flushes buffers and closes the file, releasing the resource.
Sample run (input: A 100 200 1500, B 150 250 1502, C 200 300 1498) produces output:
Station records:
A (100.00, 200.00, 1500.00)
B (150.00, 250.00, 1502.00)
C (200.00, 300.00, 1498.00)
Explain the relationship between pointers and arrays in C. Given the declaration int arr[5] = {12, 24, 36, 48, 60}; and int *p = arr;, evaluate each of the following and state the value (assume arr starts at address 2000 and sizeof(int) = 4):
*p*(p + 2)*(arr + 3)p + 1(as an address)*(p + 4) - *p
Also write a C function int sumArray(int *a, int n) that returns the sum of n integers using pointer arithmetic, and dry-run it for the given array.
Pointers and arrays relationship: The name of an array decays to a pointer to its first element. Thus arr is equivalent to &arr[0], and arr[i] is identical to *(arr + i). Pointer arithmetic scales by the element size: p + i advances by i * sizeof(int) bytes.
Evaluations (arr at 2000, sizeof(int) = 4):
| Expression | Reasoning | Value |
|---|---|---|
*p | value at arr[0] | |
*(p + 2) | value at arr[2] | |
*(arr + 3) | value at arr[3] | |
p + 1 | address | |
*(p + 4) - *p |
Function using pointer arithmetic:
int sumArray(int *a, int n) {
int sum = 0, i;
for (i = 0; i < n; i++)
sum += *(a + i); // same as a[i]
return sum;
}
Dry run for arr = {12, 24, 36, 48, 60}, n = 5:
| i | *(a+i) | running sum |
|---|---|---|
| 0 | 12 | 12 |
| 1 | 24 | 36 |
| 2 | 36 | 72 |
| 3 | 48 | 120 |
| 4 | 60 | 180 |
Final returned sum: .
Section B: Short Answer Questions
Attempt all questions.
Differentiate between while and do-while loops. Write a C program using a loop to print the sum of the first natural numbers and verify the output for using the formula .
while vs do-while:
whileis entry-controlled: the condition is tested first, so the body may execute zero times.do-whileis exit-controlled: the body runs once before the condition is tested, so it executes at least once.
C program:
#include <stdio.h>
int main(void) {
int n = 10, i = 1, sum = 0;
while (i <= n) {
sum += i;
i++;
}
printf("Sum of first %d natural numbers = %d\n", n, sum);
return 0;
}
Verification for : Formula gives .
Program output:
Sum of first 10 natural numbers = 55
Final answer: sum (matches the formula).
Write a recursive C function to compute (factorial). Show the recursion call stack (unwinding) for and state the final value.
Recursive factorial function:
long factorial(int n) {
if (n <= 1) return 1; // base case
return n * factorial(n - 1); // recursive case
}
Call stack for (winding down to base case, then unwinding):
factorial(5) = 5 * factorial(4)
factorial(4) = 4 * factorial(3)
factorial(3) = 3 * factorial(2)
factorial(2) = 2 * factorial(1)
factorial(1) = 1 <- base case
Unwinding (returning values):
Final value: .
Write a C program to add two matrices and and store the result in . Given and , compute by hand.
C program (2x2 matrix addition):
#include <stdio.h>
int main(void) {
int A[2][2] = {{3,5},{7,2}};
int B[2][2] = {{1,4},{6,8}};
int C[2][2], i, j;
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
C[i][j] = A[i][j] + B[i][j];
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) printf("%d ", C[i][j]);
printf("\n");
}
return 0;
}
Hand computation ():
Program output:
4 9
13 10
Explain the purpose of strlen(), strcpy(), and strcmp() from <string.h>. For the strings char a[] = "BRIDGE"; and char b[] = "BEAM";, state the return value of strlen(a), and explain what strcmp(a, b) returns (positive, negative, or zero) and why.
String library functions:
strlen(s)returns the number of characters insexcluding the terminating\0.strcpy(dest, src)copies the stringsrc(including\0) intodest.strcmp(s1, s2)compares two strings character-by-character by ASCII value; returns if equal, a negative value ifs1 < s2, and a positive value ifs1 > s2.
For a = "BRIDGE": strlen(a) counts B-R-I-D-G-E = 6.
strcmp(a, b) with a = "BRIDGE", b = "BEAM": Compare char by char:
- Index 0:
'B'vs'B'-> equal, continue. - Index 1:
'R'(ASCII 82) vs'E'(ASCII 69) -> differ. Since ,a > b.
strcmp(a, b) returns a positive value (specifically in many implementations), because at the first differing position 'R' has a higher ASCII code than 'E'.
Final answers: strlen(a) = 6; strcmp(a, b) returns a positive value (13).
Write a C program that classifies a steel beam's deflection status. Given a measured mid-span deflection (mm) and a span (mm), the allowable deflection limit is . Print SAFE if , otherwise UNSAFE. Test it by hand for and .
C program:
#include <stdio.h>
int main(void) {
float L = 7200.0f, delta = 18.0f;
float limit = L / 360.0f;
if (delta <= limit)
printf("SAFE\n");
else
printf("UNSAFE\n");
return 0;
}
Hand test for mm, mm:
- Allowable limit mm.
- Compare: -> condition true.
- Therefore the program prints
SAFE.
Program output:
SAFE
Final answer: limit mm, mm mm, so the beam is SAFE.
Write short notes on any two of the following:
(a) Difference between structure and union in C, with memory-size illustration for a type containing one int and one float.
(b) Use of pointers to a structure (the -> operator) with a small C example computing the cross-sectional area of a rectangular column from a struct Column { float width, depth; };.
(c) break vs continue statements with a loop example showing different outputs.
(a) Structure vs Union:
| Feature | struct | union |
|---|---|---|
| Memory | Sum of all members' sizes | Size of the largest member |
| Storage | All members stored separately | All members share one memory location |
| Access | All members usable simultaneously | Only one member valid at a time |
For a type containing one int (4 bytes) and one float (4 bytes): a struct needs bytes, while a union needs only bytes. (Sizes may grow due to padding.)
(b) Pointer to structure (-> operator):
The -> operator dereferences a structure pointer and accesses a member: ptr->member is equivalent to (*ptr).member.
#include <stdio.h>
struct Column { float width, depth; }; // mm
int main(void) {
struct Column c = {300.0f, 450.0f};
struct Column *p = &c;
float area = p->width * p->depth; // mm^2
printf("Area = %.2f mm^2\n", area);
return 0;
}
For width = 300, depth = 450: area . Output: Area = 135000.00 mm^2.
(c) break vs continue:
breakterminates the loop immediately.continueskips the rest of the current iteration and proceeds to the next iteration.
for (int i = 1; i <= 5; i++) {
if (i == 3) break; // exits when i == 3
printf("%d ", i);
}
// Output: 1 2
for (int i = 1; i <= 5; i++) {
if (i == 3) continue; // skips i == 3 only
printf("%d ", i);
}
// Output: 1 2 4 5
Summary: break prints 1 2 (stops at 3); continue prints 1 2 4 5 (skips 3).
Frequently asked questions
- Where can I find the BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) question paper 2076?
- The full BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) 2076 (regular) question paper is available free on Kekkei. You can read every question online and attempt the paper under timed exam conditions.
- Does the Computer Programming in C (IOE, CT 401) 2076 paper come with solutions?
- Yes. Every question on this Computer Programming in C (IOE, CT 401) past paper includes a step-by-step solution, plus instant AI feedback when you attempt it on Kekkei.
- How many marks is the BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) 2076 paper?
- The BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) 2076 paper carries 80 full marks and is meant to be completed in 180 minutes, across 11 questions.
- Is practising this Computer Programming in C (IOE, CT 401) past paper free?
- Yes — reading and attempting this Computer Programming in C (IOE, CT 401) past paper on Kekkei is completely free.