BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) Question Paper 2080 Nepal
This is the official BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) question paper for 2080, 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 2080 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 chainage and reduced level (RL) at stations along a road alignment. Write a C program that:
- Reads the number of stations and then reads reduced levels (in metres) into an array.
- Computes and prints the highest RL, the lowest RL, and the average RL.
- Counts how many stations have an RL above the average.
Also, by hand, trace your program for the data set and show the final printed output.
Program
#include <stdio.h>
int main(void) {
int n, i, countAbove = 0;
printf("Enter number of stations: ");
scanf("%d", &n);
float rl[100], sum = 0.0f, avg;
float high, low;
for (i = 0; i < n; i++) {
printf("Enter RL of station %d (m): ", i + 1);
scanf("%f", &rl[i]);
sum += rl[i];
}
high = low = rl[0];
for (i = 1; i < n; i++) {
if (rl[i] > high) high = rl[i];
if (rl[i] < low) low = rl[i];
}
avg = sum / n;
for (i = 0; i < n; i++)
if (rl[i] > avg) countAbove++;
printf("Highest RL = %.2f m\n", high);
printf("Lowest RL = %.2f m\n", low);
printf("Average RL = %.2f m\n", avg);
printf("Stations above average = %d\n", countAbove);
return 0;
}
Hand trace for the data set , .
Sum:
Average:
Highest = m, Lowest = m.
Stations above average (): and and — that is stations. (Note and are below.)
Final printed output
Highest RL = 1250.40 m
Lowest RL = 1243.10 m
Average RL = 1247.00 m
Stations above average = 3
(a) Explain the difference between call by value and call by reference in C, with a short example of each. (4 marks)
(b) Write a user-defined C function double power(double base, int exp) that computes for any integer exponent (positive, zero, or negative) without using the library pow() function. Use it in a main() to print and . Show the computed values by hand. (6 marks)
(a) Call by value vs call by reference
| Aspect | Call by value | Call by reference |
|---|---|---|
| What is passed | A copy of the argument's value | The address of the argument |
| Effect on caller | Changes inside function do not affect original | Changes affect the original variable |
| Mechanism | Plain variables | Pointers (& and *) |
Call by value:
void inc(int x){ x = x + 1; } // caller's variable unchanged
Call by reference:
void inc(int *x){ *x = *x + 1; } // caller's variable incremented
(b) Power function
#include <stdio.h>
double power(double base, int exp) {
int negative = (exp < 0);
int e = negative ? -exp : exp;
double result = 1.0;
for (int i = 0; i < e; i++)
result *= base;
if (negative)
result = 1.0 / result;
return result;
}
int main(void) {
printf("1.5^4 = %.4f\n", power(1.5, 4));
printf("2^-3 = %.4f\n", power(2.0, -3));
return 0;
}
Hand computation
.
.
Output
1.5^4 = 5.0625
2^-3 = 0.1250
A consulting firm stores data for reinforcement bars. Each bar has: a tag (string up to 10 chars), diameter (in mm), and length (in m). Define a struct named Bar. Write a program that reads data for 3 bars into an array of structures, then computes and prints the total steel mass assuming steel unit mass .
Use the relation for a circular bar of diameter (mm) and length (m):
Demonstrate the calculation for one bar with , .
Program
#include <stdio.h>
#define PI 3.141592653589793
#define RHO 7850.0 /* kg/m^3 */
struct Bar {
char tag[11];
double diameter; /* mm */
double length; /* m */
};
int main(void) {
struct Bar b[3];
double totalMass = 0.0;
for (int i = 0; i < 3; i++) {
printf("Bar %d tag, diameter(mm), length(m): ", i + 1);
scanf("%10s %lf %lf", b[i].tag, &b[i].diameter, &b[i].length);
}
for (int i = 0; i < 3; i++) {
double d = b[i].diameter / 1000.0; /* m */
double mass = RHO * (PI * d * d / 4.0) * b[i].length;
printf("%s : %.2f kg\n", b[i].tag, mass);
totalMass += mass;
}
printf("Total steel mass = %.2f kg\n", totalMass);
return 0;
}
Sample calculation for mm m, m:
Cross-sectional area:
Mass:
For a single 20 mm bar of 12 m, mass ≈ 29.59 kg. (Equivalently the standard rule gives kg, matching within rounding.)
(a) What is a pointer? Explain the meaning of the & (address-of) and * (dereference) operators with a small example. (3 marks)
(b) Write a C function void reverse(int *arr, int n) that reverses an integer array in place using pointer notation (no array indexing with [] inside the swap). Trace its effect on the array showing the array after each swap. (5 marks)
(a) Pointer
A pointer is a variable that stores the memory address of another variable. If int x = 10; then &x gives the address of x, and a pointer int *p = &x; holds that address. The dereference operator *p accesses the value stored at that address (here 10).
int x = 10;
int *p = &x; // p holds address of x
printf("%d", *p); // prints 10
*p = 25; // changes x to 25
&gives the address of a variable.*(when applied to a pointer) gives the value at that address.
(b) Reverse function
void reverse(int *arr, int n) {
int *left = arr;
int *right = arr + (n - 1);
while (left < right) {
int temp = *left;
*left = *right;
*right = temp;
left++;
right--;
}
}
Trace on , :
| Step | left index | right index | Array after swap |
|---|---|---|---|
| Initial | 0 | 4 | {4, 9, 15, 22, 30} |
| Swap 1 | 0 ↔ 4 | {30, 9, 15, 22, 4} | |
| Swap 2 | 1 ↔ 3 | {30, 22, 15, 9, 4} | |
| Stop | left=2, right=2 | left < right false | {30, 22, 15, 9, 4} |
The middle element (index 2 = 15) stays in place. Final reversed array: {30, 22, 15, 9, 4}.
A field team records daily rainfall (mm) for one month. Write a C program that:
- Opens a text file
rainfall.txtfor reading. The first line contains the number of days ; the following lines each contain one day's rainfall value. - Reads all values, computes the total and average monthly rainfall, and finds the wettest day (1-based day number with the maximum rainfall).
- Appends a one-line summary to a file
report.txt.
Include proper file-open error checking. Then, for the sample data with values mm, compute the printed summary by hand.
Program
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE *fin = fopen("rainfall.txt", "r");
if (fin == NULL) {
printf("Error: cannot open rainfall.txt\n");
return 1;
}
int d;
fscanf(fin, "%d", &d);
double value, total = 0.0, maxVal = -1.0;
int maxDay = 0;
for (int i = 1; i <= d; i++) {
fscanf(fin, "%lf", &value);
total += value;
if (value > maxVal) { maxVal = value; maxDay = i; }
}
fclose(fin);
double avg = total / d;
FILE *fout = fopen("report.txt", "a");
if (fout == NULL) {
printf("Error: cannot open report.txt\n");
return 1;
}
fprintf(fout, "Total=%.1f mm, Avg=%.2f mm, Wettest day=%d (%.1f mm)\n",
total, avg, maxDay, maxVal);
fclose(fout);
printf("Total=%.1f mm, Avg=%.2f mm, Wettest day=%d (%.1f mm)\n",
total, avg, maxDay, maxVal);
return 0;
}
Hand computation for , :
Total:
Average:
Maximum is mm on day 4.
Printed / appended summary:
Total=50.0 mm, Avg=10.00 mm, Wettest day=4 (25.0 mm)
Section B: Short Answer Questions
Attempt all questions.
(a) List the four basic data types in C and give the typical size (in bytes) and one example value of each. (3 marks)
(b) Evaluate the following C expressions, assuming int a = 7, b = 2; and show each result with its type: (3 marks)
a / b
a % b
(float)a / b
a > b && b > 0
(a) Basic data types (typical sizes on a 32/64-bit system)
| Type | Typical size | Example value |
|---|---|---|
char | 1 byte | 'A' |
int | 4 bytes | 42 |
float | 4 bytes | 3.14f |
double | 8 bytes | 2.71828 |
(b) Expression evaluation with a = 7, b = 2:
| Expression | Result | Explanation |
|---|---|---|
a / b | 3 (int) | Integer division truncates |
a % b | 1 (int) | Remainder of is |
(float)a / b | 3.5 (float) | a cast to float first, so floating division |
a > b && b > 0 | 1 (int, true) | is true and is true, so AND is true |
In C, relational/logical expressions yield int values 1 (true) or 0 (false).
Write a C program using a switch statement that reads a soil classification code (1, 2, 3, or 4) and prints the corresponding safe bearing capacity range:
- 1 → Soft clay (50–100 kPa)
- 2 → Stiff clay (100–300 kPa)
- 3 → Loose sand (100–200 kPa)
- 4 → Dense gravel (300–600 kPa)
For any other input, print "Invalid code".
Program
#include <stdio.h>
int main(void) {
int code;
printf("Enter soil classification code (1-4): ");
scanf("%d", &code);
switch (code) {
case 1:
printf("Soft clay: 50-100 kPa\n");
break;
case 2:
printf("Stiff clay: 100-300 kPa\n");
break;
case 3:
printf("Loose sand: 100-200 kPa\n");
break;
case 4:
printf("Dense gravel: 300-600 kPa\n");
break;
default:
printf("Invalid code\n");
}
return 0;
}
Example: input 4 prints Dense gravel: 300-600 kPa; input 9 prints Invalid code. The break after each case prevents fall-through to the next case.
Write a C program that reads two matrices and prints their sum. Then, by hand, add the matrices
Program
#include <stdio.h>
int main(void) {
int A[2][2], B[2][2], C[2][2];
int i, j;
printf("Enter matrix A (4 values):\n");
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
scanf("%d", &A[i][j]);
printf("Enter matrix B (4 values):\n");
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
scanf("%d", &B[i][j]);
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
C[i][j] = A[i][j] + B[i][j];
printf("Sum:\n");
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++)
printf("%4d", C[i][j]);
printf("\n");
}
return 0;
}
Hand calculation — element-wise addition:
Output
4 9
13 10
Without using the strlen() library function, write a C function int myStrlen(char str[]) that returns the number of characters in a string. Explain how a C string is stored in memory and demonstrate the count for the string "Bridge".
Function
int myStrlen(char str[]) {
int count = 0;
while (str[count] != '\0')
count++;
return count;
}
How a C string is stored
A C string is an array of char terminated by the null character '\0' (ASCII value 0). The functions know where the string ends by scanning until they reach '\0'. The terminator occupies one extra byte that is not counted as a visible character.
For "Bridge" the memory layout is:
Index: 0 1 2 3 4 5 6
Char: 'B' 'r' 'i' 'd' 'g' 'e' '\0'
The loop increments count for indices 0 through 5 (six characters) and stops at index 6 where '\0' is found.
Result: myStrlen("Bridge") = 6 (the '\0' is not counted, though 7 bytes are stored).
(a) Differentiate between a #define macro constant and a const variable in C. (2 marks)
(b) Identify and correct the errors in the following program: (2 marks)
#include <stdio.h>
int main()
{
int radius = 5
float area;
area = 3.14 * radius * radius;
printf("Area = %d", area)
}
(a) #define vs const
#define PI 3.14 | const float PI = 3.14; |
|---|---|
| Handled by the preprocessor before compilation; pure text substitution | A real typed variable stored in memory |
| Has no data type, no memory address | Has a type and (usually) an address |
| Cannot be inspected by a debugger as a variable | Type-checked and visible to the debugger |
(b) Errors and corrections
The program has three problems:
- Missing semicolon after
int radius = 5→ should beint radius = 5; printfuses%dfor afloatvalue → should be%f(or cast).- Missing semicolon after the
printf(...)statement.
Corrected program:
#include <stdio.h>
int main()
{
int radius = 5;
float area;
area = 3.14 * radius * radius; /* = 78.50 */
printf("Area = %f", area);
return 0;
}
With radius = 5, area .
Write a recursive C function to compute the factorial of a non-negative integer . State the base case and the recursive case, and show the call stack (sequence of calls and returns) for .
Recursive function
long factorial(int n) {
if (n == 0 || n == 1) /* base case */
return 1;
return n * factorial(n - 1); /* recursive case */
}
- Base case:
factorial(0) = 1andfactorial(1) = 1— stops the recursion. - Recursive case: .
Call stack for
Calls going down (unwinding):
factorial(4) = 4 * factorial(3)
factorial(3) = 3 * factorial(2)
factorial(2) = 2 * factorial(1)
factorial(1) = 1 <- base case reached
Returns coming back up:
factorial(1) -> 1
factorial(2) -> 2 * 1 = 2
factorial(3) -> 3 * 2 = 6
factorial(4) -> 4 * 6 = 24
Result: .
Frequently asked questions
- Where can I find the BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) question paper 2080?
- The full BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) 2080 (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) 2080 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) 2080 paper?
- The BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) 2080 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.