Browse papers
A

Section A: Long Answer Questions

Attempt all questions.

5 questions
1long10 marks

A civil engineer records the daily fresh-concrete cube compressive strength (in MPa) of NN test specimens cured for 28 days. Write a complete C program that (a) reads NN and then NN 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 fck=25  MPaf_{ck} = 25\;\text{MPa}, otherwise FAIL, and finally prints the pass percentage.

Using your program logic, hand-trace the output for N=5N = 5 with the data set {27.5,  24.0,  31.2,  22.8,  29.5}\{27.5,\;24.0,\;31.2,\;22.8,\;29.5\} 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 {27.5,24.0,31.2,22.8,29.5}\{27.5, 24.0, 31.2, 22.8, 29.5\}:

  • Sum =27.5+24.0+31.2+22.8+29.5=135.0= 27.5 + 24.0 + 31.2 + 22.8 + 29.5 = 135.0 MPa.
  • Mean =135.0/5=27.00= 135.0 / 5 = 27.00 MPa.
  • Max =31.2= 31.2 MPa, Min =22.8= 22.8 MPa.
  • Classification against fck=25f_{ck}=25 MPa:
SpecimenStrength (MPa)Result
127.5PASS
224.0FAIL
331.2PASS
422.8FAIL
529.5PASS
  • Passes =3= 3, so pass percentage =100×3/5=60.00%= 100 \times 3/5 = \mathbf{60.00\%}.

Final answer: Mean =27.00= \mathbf{27.00} MPa, Max =31.2= \mathbf{31.2} MPa, Min =22.8= \mathbf{22.8} MPa, Pass percentage =60.00%= \mathbf{60.00\%}.

control-structuresloopscivil-application
2long10 marks

(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 f(x)=x3x2=0f(x) = x^3 - x - 2 = 0 in the interval [a,b][a, b] using the bisection method, stopping when the interval half-width is below tol. Then hand-compute the first three iterations starting from [1,2][1, 2] 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, f(x)=x3x2f(x) = x^3 - x - 2, start [1,2][1, 2]:

  • f(1)=112=2f(1) = 1 - 1 - 2 = -2 (negative), f(2)=822=4f(2) = 8 - 2 - 2 = 4 (positive). Root lies in [1,2][1,2].

Iteration 1: m1=(1+2)/2=1.5m_1 = (1+2)/2 = 1.5. f(1.5)=3.3751.52=0.125f(1.5) = 3.375 - 1.5 - 2 = -0.125 (negative). Since f(1.5)f(1.5) and f(2)f(2) differ in sign, root in [1.5,2][1.5, 2].

Iteration 2: m2=(1.5+2)/2=1.75m_2 = (1.5+2)/2 = 1.75. f(1.75)=5.3593751.752=1.609375f(1.75) = 5.359375 - 1.75 - 2 = 1.609375 (positive). Root in [1.5,1.75][1.5, 1.75].

Iteration 3: m3=(1.5+1.75)/2=1.625m_3 = (1.5+1.75)/2 = 1.625. f(1.625)=4.2910156251.6252=0.666015625f(1.625) = 4.291015625 - 1.625 - 2 = 0.666015625 (positive). Root in [1.5,1.625][1.5, 1.625].

Approximate root after 3 iterations (1.5+1.625)/2=1.5625\approx (1.5 + 1.625)/2 = \mathbf{1.5625}. (The true root is 1.5214\approx 1.5214.)

functionsrecursionnumerical-methods
3long10 marks

In stiffness-method structural analysis, member forces are obtained from a matrix product. Write a complete C program that multiplies a 3×33 \times 3 stiffness matrix [K][K] by a 3×13 \times 1 displacement vector {d}\{d\} to produce the force vector {F}=[K]{d}\{F\} = [K]\{d\}.

Then compute {F}\{F\} by hand for

[K]=[410141014],{d}=[213].[K] = \begin{bmatrix} 4 & -1 & 0 \\ -1 & 4 & -1 \\ 0 & -1 & 4 \end{bmatrix},\qquad \{d\} = \begin{bmatrix} 2 \\ 1 \\ 3 \end{bmatrix}.

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 {F}=[K]{d}\{F\} = [K]\{d\}:

  • F1=(4)(2)+(1)(1)+(0)(3)=81+0=7F_1 = (4)(2) + (-1)(1) + (0)(3) = 8 - 1 + 0 = 7.
  • F2=(1)(2)+(4)(1)+(1)(3)=2+43=1F_2 = (-1)(2) + (4)(1) + (-1)(3) = -2 + 4 - 3 = -1.
  • F3=(0)(2)+(1)(1)+(4)(3)=01+12=11F_3 = (0)(2) + (-1)(1) + (4)(3) = 0 - 1 + 12 = 11.
{F}=[7111].\{F\} = \begin{bmatrix} 7 \\ -1 \\ 11 \end{bmatrix}.

Final answer: {F}=[7,  1,  11]T\{F\} = \mathbf{[\,7,\;-1,\;11\,]^{T}}.

arraysmatricesstructural-analysis
4long10 marks

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 nn 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 =1245.30+1248.75+1242.10+1250.60=4986.75= 1245.30 + 1248.75 + 1242.10 + 1250.60 = 4986.75 m.
  • Average =4986.75/4=1246.68751246.69= 4986.75 / 4 = 1246.6875 \approx 1246.69 m.
  • Highest RL == D at 1250.60 m.

Final answer: Highest-RL station is D(1250.60m)\mathbf{D\,(1250.60\,\text{m})}; average RL =1246.69= \mathbf{1246.69} m.

structurespointerscivil-application
5long10 marks

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 >0> 0 mm), and (c) the maximum daily rainfall. Handle the case where the file cannot be opened.

If the file contains the values 0,  12.5,  0,  30.0,  8.0,  0,  45.5,  5.00,\;12.5,\;0,\;30.0,\;8.0,\;0,\;45.5,\;5.0 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 {0,12.5,0,30.0,8.0,0,45.5,5.0}\{0, 12.5, 0, 30.0, 8.0, 0, 45.5, 5.0\}:

  • Total =0+12.5+0+30.0+8.0+0+45.5+5.0=101.0= 0 + 12.5 + 0 + 30.0 + 8.0 + 0 + 45.5 + 5.0 = 101.0 mm.
  • Rainy days (value >0> 0): 12.5,30.0,8.0,45.5,5.012.5, 30.0, 8.0, 45.5, 5.0 \Rightarrow 5 days.
  • Maximum daily rainfall =45.5= 45.5 mm.

Final answer: Total =101.00= \mathbf{101.00} mm, Rainy days =5= \mathbf{5}, Maximum =45.50= \mathbf{45.50} mm.

file-handlingdata-processingcivil-application
B

Section B: Short Answer Questions

Attempt all questions.

6 questions
6short5 marks

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, result=14\mathbf{result = 14}.

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, result=13.5\mathbf{result = 13.5}.

The difference arises solely from integer division truncating 7/27/2 to 33 rather than 3.53.5. Multiplication/division bind tighter than addition/subtraction, so they are computed first.

c-fundamentalsdata-typesoperators
7short5 marks

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.

control-structuresswitch-casecivil-application
8short5 marks

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; p points to x, q points to y.
  • *p = *p + *q =10+20=30= 10 + 20 = 30, so x = 30.
  • *q = *p - *q =3020=10= 30 - 20 = 10, so y = 10.
  • *p = *p - *q =3010=20= 30 - 10 = 20, so x = 20.

Output: x = 20, y = 10. The program swaps the two values using arithmetic through pointers, with no temporary variable.

pointersmemoryc-fundamentals
9short5 marks

Write a C function double meanRL(double rl[], int n) that returns the average of nn reduced-level readings passed as an array. Show how it is called from main, and hand-compute the result for the readings {100.50,  101.20,  99.80,  100.50}\{100.50,\;101.20,\;99.80,\;100.50\} 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 {100.50,101.20,99.80,100.50}\{100.50, 101.20, 99.80, 100.50\}:

  • Sum =100.50+101.20+99.80+100.50=402.00= 100.50 + 101.20 + 99.80 + 100.50 = 402.00 m.
  • Mean =402.00/4=100.50= 402.00 / 4 = 100.50 m.

Final answer: Mean RL =100.50= \mathbf{100.50} m.

functionsarrayscivil-application
10short5 marks

Write a C program that uses a loop to compute the factorial of a non-negative integer nn entered by the user, and uses it to evaluate the number of ways to arrange nn distinct survey points (i.e. n!n!). Hand-compute the output for n=6n = 6.

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 n=6n = 6:

6!=6×5×4×3×2×1.6! = 6 \times 5 \times 4 \times 3 \times 2 \times 1.

Step by step: 1×2=21 \times 2 = 2; 2×3=62 \times 3 = 6; 6×4=246 \times 4 = 24; 24×5=12024 \times 5 = 120; 120×6=720120 \times 6 = 720.

Final answer: 6!=7206! = \mathbf{720} arrangements.

loopsalgorithmsnumerical-methods
11short5 marks

Write a C program that searches a one-dimensional array of nn 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 {4,9,17,23,8}\{4, 9, 17, 23, 8\}, 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 {4,9,17,23,8}\{4, 9, 17, 23, 8\}:

ComparisonIndexa[i]Match?
104no
219no
3217yes -> stop

The key is found at index 2 after 3 comparisons.

Final answer: Output is Found at index 2; number of comparisons =3= \mathbf{3}.

arrayssearchingstring-handling

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.