BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) Question Paper 2077 Nepal
This is the official BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) question paper for 2077, 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 2077 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt all questions.
A surveyor records the chainage (in metres) of points along a road centre-line. Write a C program that:
(a) reads the number of points and then reads chainage readings into an array,
(b) computes and prints the total length of the surveyed stretch (difference between the last and first readings),
(c) computes the average spacing between consecutive points, and
(d) reports how many spacings exceed .
Assume the readings are entered in increasing order. Explain the role of the loop(s) used.
Program
#include <stdio.h>
int main(void) {
int n, i, count = 0;
float ch[100], spacing, total, avg;
printf("Enter number of points: ");
scanf("%d", &n);
printf("Enter %d chainage readings (m):\n", n);
for (i = 0; i < n; i++)
scanf("%f", &ch[i]);
/* (b) total length */
total = ch[n - 1] - ch[0];
/* (c) average spacing and (d) count > 20 m */
for (i = 1; i < n; i++) {
spacing = ch[i] - ch[i - 1];
if (spacing > 20.0f)
count++;
}
avg = total / (n - 1); /* n-1 intervals */
printf("Total length = %.2f m\n", total);
printf("Average spacing = %.2f m\n", avg);
printf("Spacings > 20 m = %d\n", count);
return 0;
}
Worked example. For and readings m:
- Total length .
- Intervals . Spacings: m.
- Average spacing .
- Spacings m: .
Role of loops. The first for loop is an input loop that fills the array index-by-index. The second for loop is a processing loop that walks adjacent pairs ch[i]-ch[i-1]; it both accumulates the count of large gaps and conceptually drives the spacing analysis. Using in the average reflects that points define intervals.
Differentiate between call by value and call by reference in C with a clear example of each. Then write a C function gcd() using recursion to find the greatest common divisor of two positive integers, and trace its execution for gcd(48, 36).
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 | Original variable unchanged | Original variable can be modified |
| Parameter type | Ordinary variable | Pointer |
Call by value example (swap fails to affect caller):
void swap(int a, int b){ int t=a; a=b; b=t; } /* caller unchanged */
Call by reference example (swap works):
void swap(int *a, int *b){ int t=*a; *a=*b; *b=t; } /* call: swap(&x,&y); */
Recursive GCD (Euclid's algorithm)
int gcd(int a, int b) {
if (b == 0)
return a; /* base case */
return gcd(b, a % b); /* recursive case */
}
Trace of gcd(48, 36) (using ):
| Call | a | b | a % b | Returns |
|---|---|---|---|---|
| 1 | 48 | 36 | 12 | gcd(36,12) |
| 2 | 36 | 12 | 0 | gcd(12,0) |
| 3 | 12 | 0 | — | 12 (base case) |
The result unwinds back up the call stack, giving .
In a structural analysis problem the stiffness contributions of three members at a joint are stored in two matrices and . Write a C program to read two matrices and print their sum and their transpose of the sum. Demonstrate the output for:
Program
#include <stdio.h>
#define N 3
int main(void) {
int A[N][N], B[N][N], C[N][N], i, j;
printf("Enter matrix A (%d values):\n", N*N);
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
scanf("%d", &A[i][j]);
printf("Enter matrix B (%d values):\n", N*N);
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
scanf("%d", &B[i][j]);
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
C[i][j] = A[i][j] + B[i][j];
printf("Sum C = A + B:\n");
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) printf("%4d", C[i][j]);
printf("\n");
}
printf("Transpose of C:\n");
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) printf("%4d", C[j][i]);
printf("\n");
}
return 0;
}
Computed output. Element-wise addition :
Verification of a few entries: , , .
Transpose (swap rows and columns, ):
Define a C structure named Beam to store the id (int), length in metres (float) and uniform load in kN/m (float) of a simply supported beam. Write a program that reads details of beams into an array of structures, computes the maximum bending moment of each beam using , and prints the beam with the largest maximum moment. Show the working for two beams: Beam 101 () and Beam 102 ().
Program
#include <stdio.h>
struct Beam {
int id;
float length; /* m */
float load; /* kN/m */
};
int main(void) {
int n, i, maxIndex = 0;
struct Beam b[50];
float m, maxM;
printf("Enter number of beams: ");
scanf("%d", &n);
for (i = 0; i < n; i++) {
printf("Beam %d -> id length load: ", i + 1);
scanf("%d %f %f", &b[i].id, &b[i].length, &b[i].load);
}
maxM = (b[0].load * b[0].length * b[0].length) / 8.0f;
for (i = 1; i < n; i++) {
m = (b[i].load * b[i].length * b[i].length) / 8.0f;
if (m > maxM) { maxM = m; maxIndex = i; }
}
printf("Beam %d has the largest Mmax = %.2f kN.m\n",
b[maxIndex].id, maxM);
return 0;
}
Worked calculation using :
- Beam 101: .
- Beam 102: .
Since , the program prints Beam 102 with the largest maximum moment of .
A laboratory stores concrete cube test results in a text file cubes.txt, each line containing a cube id and its crushing load in kN. Write a C program that:
(a) opens the file for reading (handle the case where the file cannot be opened),
(b) reads each record until end-of-file,
(c) converts each crushing load to compressive strength in MPa using a cube (), and
(d) writes id, load and strength to an output file report.txt.
Show a sample numeric conversion for a load of .
Program
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE *fin, *fout;
int id;
float load, strength;
int area = 150 * 150; /* mm^2 */
fin = fopen("cubes.txt", "r");
if (fin == NULL) {
printf("Error: cannot open cubes.txt\n");
return 1;
}
fout = fopen("report.txt", "w");
if (fout == NULL) {
printf("Error: cannot create report.txt\n");
fclose(fin);
return 1;
}
fprintf(fout, "ID\tLoad(kN)\tStrength(MPa)\n");
while (fscanf(fin, "%d %f", &id, &load) == 2) {
strength = (load * 1000.0f) / area; /* N/mm^2 = MPa */
fprintf(fout, "%d\t%.2f\t\t%.2f\n", id, load, strength);
}
fclose(fin);
fclose(fout);
printf("Report generated in report.txt\n");
return 0;
}
Sample conversion for load on a mm cube:
Since , the strength is 25.00 MPa. The fscanf return value of 2 confirms two fields were read successfully and terminates the loop at end-of-file.
Section B: Short Answer Questions
Attempt all questions.
Predict and justify the output of the following C program. Explain the effect of integer division and operator precedence.
#include <stdio.h>
int main(void) {
int a = 7, b = 2;
float c;
c = a / b;
printf("%.2f\n", c);
c = (float)a / b;
printf("%.2f\n", c);
printf("%d\n", a % b + b * 2);
return 0;
}
Output
3.00
3.50
5
Justification.
c = a / b;— bothaandbareint, so7 / 2is integer division giving3(the fractional part is discarded before assignment). Storing into thefloat cthen prints3.00.c = (float)a / b;— the cast promotesato7.0, forcing floating-point division: , printed as3.50.a % b + b * 2— by precedence,%and*bind tighter than+. So , , then .
Key lesson: type of operands, not the type of the destination, determines whether division is integer or floating point.
Explain the relationship between arrays and pointers in C. Write a C function float average(float *arr, int n) that returns the average of n float values using pointer arithmetic (no array subscript []), and show how it is called for the array {12.5, 15.0, 9.5, 18.0}.
Array–pointer relationship. The name of an array decays to a pointer to its first element: for float a[4], the expression a is equivalent to &a[0], and a[i] is exactly *(a + i). Pointer arithmetic scales by the element size automatically, so arr + 1 advances by one float.
Function using pointer arithmetic
float average(float *arr, int n) {
float sum = 0.0f;
int i;
for (i = 0; i < n; i++)
sum += *(arr + i); /* same as arr[i] */
return sum / n;
}
Call
float data[] = {12.5, 15.0, 9.5, 18.0};
printf("Average = %.2f\n", average(data, 4));
Result. Sum ; average . The program prints Average = 13.75.
Write a C program that classifies a soil sample by its plasticity index entered by the user using a switch-like decision (you may use if-else if):
- : Low plasticity
- : Medium plasticity
- : High plasticity
State the output for .
Program
#include <stdio.h>
int main(void) {
float PI;
printf("Enter plasticity index PI: ");
scanf("%f", &PI);
if (PI < 7.0f)
printf("Low plasticity\n");
else if (PI < 17.0f) /* 7 <= PI < 17 */
printf("Medium plasticity\n");
else
printf("High plasticity\n");
return 0;
}
Note on switch. A switch works only on integer/character constant labels, so it cannot test ranges directly; the natural tool for continuous ranges is the if-else if ladder shown above. (One could switch on an integer band code, e.g. (int)(PI/7), but the ladder is clearer.)
Output for . Since is not but is , the second branch executes, printing:
Medium plasticity
Write a C function to compute the factorial of a non-negative integer iteratively, and use it inside main() to evaluate the number of ways . Compute by hand to verify your program.
Program
#include <stdio.h>
long factorial(int x) {
long f = 1;
int i;
for (i = 2; i <= x; i++)
f *= i;
return f; /* factorial(0)=factorial(1)=1 */
}
int main(void) {
int n, r;
long nCr;
printf("Enter n and r: ");
scanf("%d %d", &n, &r);
nCr = factorial(n) / (factorial(r) * factorial(n - r));
printf("C(%d,%d) = %ld\n", n, r, nCr);
return 0;
}
Hand verification of :
where , and . The program prints C(6,2) = 15.
Without using the <string.h> library, write a C program that counts the number of vowels and the total length of a string entered by the user. Show the output for the input Tribhuvan.
Program
#include <stdio.h>
int main(void) {
char str[100], ch;
int i = 0, vowels = 0, len = 0;
printf("Enter a string: ");
scanf("%99s", str); /* reads one word */
while (str[i] != '\0') {
ch = str[i];
if (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||
ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
vowels++;
len++;
i++;
}
printf("Length = %d\n", len);
printf("Vowels = %d\n", vowels);
return 0;
}
Output for Tribhuvan. The string has characters T r i b h u v a n.
- Length (loop stops at the
'\0'terminator). - Vowels:
i,u,a3.
Length = 9
Vowels = 3
Define an algorithm and a flowchart. Draw a flowchart and write the algorithm to find the largest of three numbers , , . Trace it for , , .
Definitions. An algorithm is a finite, ordered sequence of unambiguous steps that solves a problem. A flowchart is a graphical representation of an algorithm using standard symbols (oval = start/stop, parallelogram = input/output, rectangle = process, diamond = decision).
Algorithm (largest of three)
Step 1: Start
Step 2: Read a, b, c
Step 3: If a >= b and a >= c, then large = a
Step 4: Else if b >= c, then large = b
Step 5: Else large = c
Step 6: Print large
Step 7: Stop
Flowchart (ASCII)
( Start )
|
[ Read a, b, c ]
|
< a>=b && a>=c? > --yes--> [ large = a ]--+
| no |
< b>=c? > --------yes--> [ large = b ]-----+
| no |
[ large = c ]------------------------------+
|
[ Print large ]
|
( Stop )
Trace for , , :
- Is and ? is false skip.
- Is ? is true
large = b = 27. - Output: 27.
The largest number is .
Frequently asked questions
- Where can I find the BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) question paper 2077?
- The full BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) 2077 (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) 2077 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) 2077 paper?
- The BE Civil Engineering (IOE, TU) Computer Programming in C (IOE, CT 401) 2077 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.