BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) Question Paper 2078 Nepal
This is the official BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) question paper for 2078, 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 2078 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt all questions.
A civil engineering survey records the daily concrete strength gain (in MPa) of a curing cylinder over a number of days. Write a C program that:
(a) Reads an integer (number of days) from the user, then reads daily strength values (floating point).
(b) Computes and prints the total, the average, the maximum, and the minimum strength using appropriate loops.
(c) Counts how many days the strength was greater than or equal to the design strength of 25 MPa.
Explain the difference between an entry-controlled and an exit-controlled loop, and state which loop construct you used in part (b) and why.
Program
#include <stdio.h>
int main(void) {
int n, i, daysAbove = 0;
float strength, total = 0.0f, avg;
float maxS, minS;
const float DESIGN = 25.0f;
printf("Enter number of days: ");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
printf("Enter strength for day %d (MPa): ", i);
scanf("%f", &strength);
total += strength;
if (i == 1) { /* initialise max/min with first reading */
maxS = minS = strength;
} else {
if (strength > maxS) maxS = strength;
if (strength < minS) minS = strength;
}
if (strength >= DESIGN) daysAbove++;
}
avg = total / n;
printf("\nTotal strength = %.2f MPa\n", total);
printf("Average strength = %.2f MPa\n", avg);
printf("Maximum strength = %.2f MPa\n", maxS);
printf("Minimum strength = %.2f MPa\n", minS);
printf("Days >= 25 MPa = %d\n", daysAbove);
return 0;
}
Sample run (for with readings 18.0, 22.5, 25.0, 27.5, 30.0 MPa):
- Total MPa
- Average MPa
- Maximum MPa, Minimum MPa
- Days MPa
Entry-controlled vs exit-controlled loop:
| Aspect | Entry-controlled | Exit-controlled |
|---|---|---|
| Test position | Condition checked before body | Condition checked after body |
| Examples | for, while | do...while |
| Minimum executions | 0 (body may never run) | 1 (body runs at least once) |
I used a for loop in part (b) because the number of iterations is known in advance; for keeps the initialisation, condition, and update neatly in one place, which reduces the chance of forgetting the counter update.
(a) Differentiate between call by value and call by reference in C with a clear example of each.
(b) Write a C program that uses a user-defined function power(base, exp) (using recursion) to compute for integer exponents. Use it to compute the volume of a cube of side 6 m as .
(c) Show the recursion trace (stack of calls) for power(6, 3).
(a) Call by value vs call by reference
- Call by value: a copy of the argument is passed; changes inside the function do not affect the caller's variable.
- Call by reference: the address is passed (via pointers); changes inside the function do affect the caller's variable.
/* call by value: swap does NOT work */
void swapVal(int a, int b) { int t = a; a = b; b = t; }
/* call by reference: swap DOES work */
void swapRef(int *a, int *b) { int t = *a; *a = *b; *b = t; }
After swapVal(x, y) the caller's x, y are unchanged; after swapRef(&x, &y) they are swapped.
(b) Recursive power and cube volume
#include <stdio.h>
long power(int base, int exp) {
if (exp == 0) return 1; /* base case */
return base * power(base, exp - 1); /* recursive case */
}
int main(void) {
int side = 6;
long volume = power(side, 3);
printf("Volume of cube = %ld cubic metres\n", volume);
return 0;
}
(c) Recursion trace for power(6, 3)
power(6,3) = 6 * power(6,2)
= 6 * (6 * power(6,1))
= 6 * (6 * (6 * power(6,0)))
= 6 * (6 * (6 * 1)) <- base case returns 1
= 6 * (6 * 6)
= 6 * 36
= 216
Unwinding: power(6,0)=1, power(6,1)=6, power(6,2)=36, power(6,3)=216.
Final answer: Volume of the cube .
A structural engineer stores nodal loads in two matrices and (in kN). Write a C program that reads two matrices and prints their sum . Then, by hand, compute for:
Program
#include <stdio.h>
#define R 2
#define C 3
int main(void) {
int A[R][C], B[R][C], S[R][C];
int i, j;
printf("Enter matrix A (%d values):\n", R*C);
for (i = 0; i < R; i++)
for (j = 0; j < C; j++)
scanf("%d", &A[i][j]);
printf("Enter matrix B (%d values):\n", R*C);
for (i = 0; i < R; i++)
for (j = 0; j < C; j++)
scanf("%d", &B[i][j]);
for (i = 0; i < R; i++)
for (j = 0; j < C; j++)
S[i][j] = A[i][j] + B[i][j];
printf("Sum matrix C = A + B:\n");
for (i = 0; i < R; i++) {
for (j = 0; j < C; j++)
printf("%4d", S[i][j]);
printf("\n");
}
return 0;
}
Hand computation (element-wise addition):
Define a C structure named Beam to store: a beam ID (integer), length in metres (float), and uniformly distributed load (UDL) in kN/m (float). Write a program that reads data for 3 beams into an array of structures, then for each beam computes and prints the maximum bending moment for a simply supported beam under UDL, given by .
Program
#include <stdio.h>
struct Beam {
int id;
float length; /* metres */
float udl; /* kN/m */
};
int main(void) {
struct Beam beams[3];
int i;
float Mmax;
for (i = 0; i < 3; i++) {
printf("Beam %d - enter id, length(m), UDL(kN/m): ", i + 1);
scanf("%d %f %f", &beams[i].id, &beams[i].length, &beams[i].udl);
}
printf("\nID L(m) w(kN/m) Mmax(kN.m)\n");
for (i = 0; i < 3; i++) {
Mmax = (beams[i].udl * beams[i].length * beams[i].length) / 8.0f;
printf("%-4d %-6.2f %-7.2f %.2f\n",
beams[i].id, beams[i].length, beams[i].udl, Mmax);
}
return 0;
}
Worked example for a beam with , :
For a beam with , :
The structure groups related, differently-typed data under one logical unit, and the array of structures lets the same processing loop run for every beam.
A site office logs rainfall data. Write a C program that:
(a) Opens a file rainfall.txt for writing, writes 5 rainfall readings (in mm) entered by the user, then closes it.
(b) Re-opens the same file for reading, reads back all values, and computes the total and average rainfall.
Explain the purpose of fopen, fprintf, fscanf, and fclose, and what happens if fopen fails.
Program
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE *fp;
int i;
float value, total = 0.0f, avg;
/* (a) write phase */
fp = fopen("rainfall.txt", "w");
if (fp == NULL) {
printf("Error: cannot open file for writing.\n");
return 1;
}
for (i = 1; i <= 5; i++) {
printf("Enter rainfall reading %d (mm): ", i);
scanf("%f", &value);
fprintf(fp, "%f\n", value);
}
fclose(fp);
/* (b) read phase */
fp = fopen("rainfall.txt", "r");
if (fp == NULL) {
printf("Error: cannot open file for reading.\n");
return 1;
}
for (i = 0; i < 5; i++) {
fscanf(fp, "%f", &value);
total += value;
}
fclose(fp);
avg = total / 5.0f;
printf("Total rainfall = %.2f mm\n", total);
printf("Average rainfall = %.2f mm\n", avg);
return 0;
}
Worked example for readings 8.0, 12.0, 5.0, 20.0, 15.0 mm:
- Total mm
- Average
Function roles:
fopen(name, mode)— opens a file in the given mode ("w","r", etc.) and returns aFILE *pointer (orNULLon failure).fprintf(fp, ...)— writes formatted data to the file.fscanf(fp, ...)— reads formatted data from the file.fclose(fp)— flushes buffers and releases the file resource.
If fopen fails it returns NULL (e.g., disk full, permission denied, path missing). The program must check for NULL before using the pointer; otherwise dereferencing a NULL FILE * causes a runtime crash.
Section B: Short Answer Questions
Attempt all questions.
(a) List the four basic data types in C and give a typical size (in bytes) and one civil-engineering use for each.
(b) Evaluate the following C expression step by step, stating the result and its type, assuming int a = 7, b = 2;:
(a) Basic data types
| Type | Typical size | Civil use |
|---|---|---|
char | 1 byte | Storing a soil-class label (e.g. 'A') |
int | 4 bytes | Counting number of bars/storeys |
float | 4 bytes | Concrete strength in MPa |
double | 8 bytes | High-precision survey coordinates |
(b) Expression evaluation of a / b + 5.0 * a % b with a = 7, b = 2:
Precedence: *, /, % (left-to-right) before +.
a / b(integer division, resultint).5.0 * a(double).35.0 % b— the%operator is not valid on adouble. In C, modulus requires integer operands, so5.0 * a % bwould cause a compile-time error.
If the intended expression were a / b + 5 * a % b (all int):
a / b = 35 * a = 35, then35 % 2 = 13 + 1 = 4
Result (integer version): , type int. (The original mixes double with %, which is illegal — a key teaching point.)
Write a C program using a switch statement that classifies a concrete grade based on a single character input: 'A' prints "M20", 'B' prints "M25", 'C' prints "M30", and any other input prints "Invalid grade". Explain why a break statement is needed after each case.
Program
#include <stdio.h>
int main(void) {
char grade;
printf("Enter grade code (A/B/C): ");
scanf(" %c", &grade);
switch (grade) {
case 'A':
printf("M20\n");
break;
case 'B':
printf("M25\n");
break;
case 'C':
printf("M30\n");
break;
default:
printf("Invalid grade\n");
}
return 0;
}
Sample: input 'B' prints M25; input 'X' prints Invalid grade.
Why break is needed: Without break, control falls through to the next case after a match, executing subsequent cases until a break or the end of the switch is reached. For example, without breaks, input 'A' would print M20, then M25, then M30. The break exits the switch immediately after the matching case so only the intended output is produced.
(a) What is a pointer? Explain the & (address-of) and * (dereference) operators.
(b) For the following code, state the printed output and explain why:
int x = 42;
int *p = &x;
*p = *p + 8;
printf("%d\n", x);
(a) Pointer
A pointer is a variable that stores the memory address of another variable rather than a direct value.
- The
&(address-of) operator returns the memory address of a variable, e.g.&xgives the location ofx. - The
*(dereference / indirection) operator accesses the value stored at the address a pointer holds, e.g.*preads or writes the variable thatppoints to.
(b) Output trace
int x = 42; // x holds 42
int *p = &x; // p now points to x
*p = *p + 8; // *p reads 42, adds 8 -> writes 50 into x
printf("%d\n", x); // prints x
Since p points to x, writing through *p changes x itself: .
Printed output: .
Write a C program that searches a 1-D array of integers for a key value using linear search and prints its position (1-based) or "Not found". Then dry-run the search for key = 17 on the array and show the comparisons made.
Program
#include <stdio.h>
int main(void) {
int arr[100], n, i, key, pos = -1;
printf("Enter n: ");
scanf("%d", &n);
printf("Enter %d values: ", n);
for (i = 0; i < n; i++)
scanf("%d", &arr[i]);
printf("Enter key to search: ");
scanf("%d", &key);
for (i = 0; i < n; i++) {
if (arr[i] == key) {
pos = i + 1; /* 1-based position */
break;
}
}
if (pos != -1)
printf("Found at position %d\n", pos);
else
printf("Not found\n");
return 0;
}
Dry run for key = 17, array :
| Step | Index | arr[i] | Compare with 17 | Result |
|---|---|---|---|---|
| 1 | 0 | 4 | ? | No |
| 2 | 1 | 9 | ? | No |
| 3 | 2 | 17 | ? | Yes |
Match found at index , so 1-based position .
Output: Found at position (after 3 comparisons).
Write a user-defined C function float area_circle(float r) that returns the cross-sectional area of a circular column of radius . Call it from main to compute the area of a column of radius m. Use and show the hand calculation.
Program
#include <stdio.h>
#define PI 3.1416f
float area_circle(float r) {
return PI * r * r;
}
int main(void) {
float r = 0.30f;
float A = area_circle(r);
printf("Cross-sectional area = %.4f square metres\n", A);
return 0;
}
Hand calculation for m:
Rounded to four decimal places:
Cross-sectional area .
(a) Explain the steps of the C program execution cycle: editing, preprocessing, compiling, linking, and execution.
(b) Identify and correct the three errors in the program below:
#include <stdio.h>
int main() {
int n = 5
printf("Square = %d", n * n)
return 0
}
(a) C program execution cycle
- Editing — the source code is typed and saved in a
.cfile using an editor/IDE. - Preprocessing — the preprocessor handles directives such as
#includeand#define, producing an expanded source file. - Compiling — the compiler translates the preprocessed source into object code (
.o/.obj), checking syntax. - Linking — the linker combines object code with library functions (e.g.
printffrom the standard library) to create an executable. - Execution — the operating system loads and runs the executable; output is produced.
Flow: source.c → preprocessor → compiler → linker → executable → run.
(b) Error correction
The three errors are missing semicolons at the end of statements.
#include <stdio.h>
int main() {
int n = 5; /* error 1: added ; */
printf("Square = %d", n * n); /* error 2: added ; */
return 0; /* error 3: added ; */
}
With the corrections the program compiles and prints: Square = 25 (since ).
Frequently asked questions
- Where can I find the BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) question paper 2078?
- The full BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) 2078 (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) 2078 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) 2078 paper?
- The BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) 2078 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.