BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) Question Paper 2079 Nepal
This is the official BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) question paper for 2079, 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 2079 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt all questions.
A civil engineer records the daily fresh-concrete cube compressive strength (in MPa) of test specimens cured for 28 days. Write a complete C program that (a) reads and then strength values into an array, (b) computes and prints the mean strength, the maximum and minimum strength, and (c) classifies each specimen as PASS if its strength is at least the target characteristic strength , otherwise FAIL, and finally prints the pass percentage.
Using your program logic, hand-trace the output for with the data set MPa.
Program
#include <stdio.h>
int main(void) {
int N, i, pass = 0;
float s[100], sum = 0.0f, mean, mx, mn;
printf("Enter number of specimens: ");
scanf("%d", &N);
for (i = 0; i < N; i++) {
printf("Strength of specimen %d (MPa): ", i + 1);
scanf("%f", &s[i]);
sum += s[i];
}
mean = sum / N;
mx = mn = s[0];
for (i = 1; i < N; i++) {
if (s[i] > mx) mx = s[i];
if (s[i] < mn) mn = s[i];
}
for (i = 0; i < N; i++) {
if (s[i] >= 25.0f) {
printf("Specimen %d: %.1f MPa -> PASS\n", i + 1, s[i]);
pass++;
} else {
printf("Specimen %d: %.1f MPa -> FAIL\n", i + 1, s[i]);
}
}
printf("Mean strength = %.2f MPa\n", mean);
printf("Max = %.2f MPa, Min = %.2f MPa\n", mx, mn);
printf("Pass percentage = %.2f %%\n", 100.0f * pass / N);
return 0;
}
Hand trace for the given data :
- Sum MPa.
- Mean MPa.
- Max MPa, Min MPa.
- Classification against MPa:
| Specimen | Strength (MPa) | Result |
|---|---|---|
| 1 | 27.5 | PASS |
| 2 | 24.0 | FAIL |
| 3 | 31.2 | PASS |
| 4 | 22.8 | FAIL |
| 5 | 29.5 | PASS |
- Passes , so pass percentage .
Final answer: Mean MPa, Max MPa, Min MPa, Pass percentage .
(a) Differentiate between call by value and call by reference in C with a small illustrative example of each.
(b) Write a C function double bisection(double a, double b, double tol) that finds a root of in the interval using the bisection method, stopping when the interval half-width is below tol. Then hand-compute the first three iterations starting from and report the approximate root.
(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); the function can modify the caller's variable.
void byVal(int x) { x = 99; } /* caller unchanged */
void byRef(int *x) { *x = 99; } /* caller changed */
If a = 5; byVal(a); then a is still 5. If byRef(&a); then a becomes 99.
(b) Bisection function
#include <math.h>
double f(double x) { return x*x*x - x - 2.0; }
double bisection(double a, double b, double tol) {
double m;
while ((b - a) / 2.0 > tol) {
m = (a + b) / 2.0;
if (f(m) == 0.0) return m;
if (f(a) * f(m) < 0.0) b = m; /* root in [a,m] */
else a = m; /* root in [m,b] */
}
return (a + b) / 2.0;
}
Hand computation, , start :
- (negative), (positive). Root lies in .
Iteration 1: . (negative). Since and differ in sign, root in .
Iteration 2: . (positive). Root in .
Iteration 3: . (positive). Root in .
Approximate root after 3 iterations . (The true root is .)
In stiffness-method structural analysis, member forces are obtained from a matrix product. Write a complete C program that multiplies a stiffness matrix by a displacement vector to produce the force vector .
Then compute by hand for
Program
#include <stdio.h>
int main(void) {
int i, j;
double K[3][3], d[3], F[3] = {0};
printf("Enter 3x3 stiffness matrix K:\n");
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
scanf("%lf", &K[i][j]);
printf("Enter displacement vector d (3 values):\n");
for (i = 0; i < 3; i++)
scanf("%lf", &d[i]);
for (i = 0; i < 3; i++) {
F[i] = 0.0;
for (j = 0; j < 3; j++)
F[i] += K[i][j] * d[j];
}
printf("Force vector F = [K]{d}:\n");
for (i = 0; i < 3; i++)
printf("F[%d] = %.2f\n", i, F[i]);
return 0;
}
Hand computation :
- .
- .
- .
Final answer: .
A surveyor stores levelling stations as a structure with a name and reduced level (RL in metres). (a) Define a struct Station holding a station name (string) and an RL. (b) Write a program that reads stations into an array of structures and, using a pointer to traverse the array, finds and prints the station with the highest RL and the average RL of all stations.
Hand-compute the highest-RL station and the average RL for: A(1245.30), B(1248.75), C(1242.10), D(1250.60).
Program
#include <stdio.h>
struct Station {
char name[20];
double rl; /* reduced level in metres */
};
int main(void) {
struct Station st[50], *p, *best;
int n, i;
double sum = 0.0;
printf("Number of stations: ");
scanf("%d", &n);
for (i = 0; i < n; i++) {
printf("Name and RL of station %d: ", i + 1);
scanf("%s %lf", st[i].name, &st[i].rl);
}
best = st; /* pointer to first element */
for (p = st; p < st + n; p++) {
sum += p->rl;
if (p->rl > best->rl) best = p;
}
printf("Highest RL station: %s (%.2f m)\n", best->name, best->rl);
printf("Average RL = %.2f m\n", sum / n);
return 0;
}
Hand computation for A(1245.30), B(1248.75), C(1242.10), D(1250.60):
- Sum m.
- Average m.
- Highest RL D at 1250.60 m.
Final answer: Highest-RL station is ; average RL m.
Rainfall data for a catchment is stored in a text file rain.txt, one daily rainfall value (mm) per line. Write a complete C program that opens the file, reads all values until end-of-file, and computes (a) the total rainfall, (b) the number of rainy days (rainfall mm), and (c) the maximum daily rainfall. Handle the case where the file cannot be opened.
If the file contains the values mm, compute the three outputs by hand.
Program
#include <stdio.h>
int main(void) {
FILE *fp = fopen("rain.txt", "r");
double v, total = 0.0, mx = 0.0;
int rainy = 0;
if (fp == NULL) {
printf("Error: cannot open rain.txt\n");
return 1;
}
while (fscanf(fp, "%lf", &v) == 1) {
total += v;
if (v > 0.0) rainy++;
if (v > mx) mx = v;
}
fclose(fp);
printf("Total rainfall = %.2f mm\n", total);
printf("Rainy days = %d\n", rainy);
printf("Maximum daily rainfall = %.2f mm\n", mx);
return 0;
}
Hand computation for :
- Total mm.
- Rainy days (value ): 5 days.
- Maximum daily rainfall mm.
Final answer: Total mm, Rainy days , Maximum mm.
Section B: Short Answer Questions
Attempt all questions.
Evaluate the following C expression by hand and state the final value of result, explaining the role of operator precedence and integer division:
int a = 7, b = 2, c = 5;
int result = a + b * c - a / b;
Also state what result would be if a, b, c were declared float instead.
Integer evaluation (precedence: * and / before + and -, left to right):
b * c = 2 * 5 = 10.a / b = 7 / 2 = 3(integer division truncates the fractional part).result = a + 10 - 3 = 7 + 10 - 3 = 14.
So with int, .
Float evaluation: With float a=7, b=2, c=5, the division is real: a/b = 3.5.
result = 7.0 + 10.0 - 3.5 = 13.5.
So with float, .
The difference arises solely from integer division truncating to rather than . Multiplication/division bind tighter than addition/subtraction, so they are computed first.
Write a C program using a switch statement that reads a soil classification code (1 = Gravel, 2 = Sand, 3 = Silt, 4 = Clay) and prints the corresponding soil type. For any other code, print an error message. Use break correctly.
Program
#include <stdio.h>
int main(void) {
int code;
printf("Enter soil code (1-4): ");
scanf("%d", &code);
switch (code) {
case 1: printf("Soil type: Gravel\n"); break;
case 2: printf("Soil type: Sand\n"); break;
case 3: printf("Soil type: Silt\n"); break;
case 4: printf("Soil type: Clay\n"); break;
default: printf("Error: invalid soil code\n");
}
return 0;
}
Explanation: Each case ends with break to prevent fall-through to the next case. The default label handles any code outside 1-4. For example, input 3 prints Soil type: Silt, and input 9 prints Error: invalid soil code.
Explain pointers in C. Hand-trace the output of the following program and state the final values printed:
#include <stdio.h>
int main(void) {
int x = 10, y = 20;
int *p = &x, *q = &y;
*p = *p + *q;
*q = *p - *q;
*p = *p - *q;
printf("x = %d, y = %d\n", x, y);
return 0;
}
Pointers: A pointer is a variable that stores the memory address of another variable. int *p = &x; makes p point to x; the dereference *p reads or writes the value at that address. Pointers enable call by reference, dynamic memory, and efficient array traversal.
Hand trace (this is the classic swap-without-temp):
- Initially
x = 10,y = 20;ppoints tox,qpoints toy. *p = *p + *q, sox = 30.*q = *p - *q, soy = 10.*p = *p - *q, sox = 20.
Output: x = 20, y = 10. The program swaps the two values using arithmetic through pointers, with no temporary variable.
Write a C function double meanRL(double rl[], int n) that returns the average of reduced-level readings passed as an array. Show how it is called from main, and hand-compute the result for the readings m.
Function and call
#include <stdio.h>
double meanRL(double rl[], int n) {
double sum = 0.0;
int i;
for (i = 0; i < n; i++)
sum += rl[i];
return sum / n;
}
int main(void) {
double rl[] = {100.50, 101.20, 99.80, 100.50};
int n = 4;
printf("Mean RL = %.2f m\n", meanRL(rl, n));
return 0;
}
The array name rl decays to a pointer when passed, so the function operates on the caller's data; n carries the element count.
Hand computation for :
- Sum m.
- Mean m.
Final answer: Mean RL m.
Write a C program that uses a loop to compute the factorial of a non-negative integer entered by the user, and uses it to evaluate the number of ways to arrange distinct survey points (i.e. ). Hand-compute the output for .
Program
#include <stdio.h>
int main(void) {
int n, i;
unsigned long long fact = 1ULL;
printf("Enter n: ");
scanf("%d", &n);
if (n < 0) {
printf("Factorial undefined for negative numbers\n");
return 1;
}
for (i = 2; i <= n; i++)
fact *= i;
printf("%d! = %llu arrangements\n", n, fact);
return 0;
}
Hand computation for :
Step by step: ; ; ; ; .
Final answer: arrangements.
Write a C program that searches a one-dimensional array of integers for a key value using linear search and prints the index where it is found (or a not-found message). Hand-trace the search for key = 17 in the array , counting the comparisons made.
Program
#include <stdio.h>
int main(void) {
int a[100], n, key, i, found = -1;
printf("Enter n: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
printf("Enter key: ");
scanf("%d", &key);
for (i = 0; i < n; i++) {
if (a[i] == key) { found = i; break; }
}
if (found != -1)
printf("Found at index %d\n", found);
else
printf("Not found\n");
return 0;
}
Hand trace for key = 17 in :
| Comparison | Index | a[i] | Match? |
|---|---|---|---|
| 1 | 0 | 4 | no |
| 2 | 1 | 9 | no |
| 3 | 2 | 17 | yes -> stop |
The key is found at index 2 after 3 comparisons.
Final answer: Output is Found at index 2; number of comparisons .
Frequently asked questions
- Where can I find the BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) question paper 2079?
- The full BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) 2079 (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) 2079 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) 2079 paper?
- The BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) 2079 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.