2079

CSC115 · TU past paper

C Programming 2079 question paper

The complete TU 2079 exam paper for C Programming (CSC115), all 12 questions with solved model answers written to the mark scheme.

Tap a question to open its answer.

  1. 110 marksFunction Arguments and Return TypesAnswer

    Why do we need a break and continue statement? Define formal argument and actual argument in function with examples. Identify and list the errors in the following code.

    int main() {
        int a, b, c
        scanf("%d%d%d, &a, &b, &c);
        sum(a, b, c);
        return -1;
    }
    
    void sum(int x, int y, int z) {
        int sum;
        sum = a + b + c;
        return sum;
    }
    

    [10]

    --- The break statement is used to immediately exit from a loop (for, while, do-while) or a switch statement before its normal termination condition is reached. Without break, a loop would continue executing even when a desired condition...

  2. 210 marksExit functionAnswer

    What is the difference between exit() and exit(1)? Discuss the need of nested structure with an example. Write a program to find the value of x^y without using POW code.[10]

    --- The exit() function is defined in <stdlib.h and is used to terminate a program immediately from any point in the code, including from inside functions or loops. Feature exit(0) exit(1) --------- Meaning Normal / successful terminatio...

  3. 310 marksDecision Making and LoopingAnswer

    Write a program to demonstrate the following menu-driven program. The user will provide an integer and alphabet for making choice and the corresponding task has to be performed according as follow:A. Find Odd or Even B. Find Positive or Negative C. Find the Factorial value D. Exit The choice will be displayed until the user will give 'D' as a choice.[10]

    --- --- --- The menu is placed inside a do-while loop so that: - The menu is displayed at least once. - The loop continues repeating until the user enters 'D' (Exit). Each menu option is handled by a separate case block: Choice Task Perf...

  4. 45 marksArithmetic operatorAnswer

    How do you swap the values of two integers without using the third temporary variable? Justify with the example. [5]

    Normally, swapping two variables requires a third temporary variable. However, we can swap two integers without a temporary variable using either: 1. Arithmetic operators (Addition and Subtraction) 2. Bitwise XOR operator --- Step Operat...

  5. 55 marksNested and Recursive FunctionAnswer

    Write a program to find the sum of digits of a given integer using recursion. [5]

    The sum of digits of a number can be found recursively by: - Base case: If the number is 0, return 0 - Recursive case: Return (number % 10) + sumOfDigits(number / 10) For example, for n = 123: - 123 % 10 = 3, then call sumOfDigits(12) - ...

  6. 65 marksConstants/ LiteralsAnswer

    Differentiate between constant and literals. Why do we need to define the type of data? [5]

    --- Basis Constant Literal --------- Definition A constant is a named memory location whose value cannot be changed during program execution. A literal is a fixed, raw value that appears directly in the source code. Has a Name? Yes, it h...

  7. 75 marksIntroduction to ArrayAnswer

    Write a program to find the second largest number in the given array of numbers. [5]

    1. Read N numbers into an array. 2. Find the largest element first. 3. Then find the largest element among all elements that are NOT equal to the largest -- that gives the second largest. --- --- --- Step What happens -------------------...
  8. 85 marksArray of structureAnswer

    Create a structure 'Employee' having Name, Address, Salary, and Age as member functions. Display the name of the employee having age between 40 and 50 and are living in Kathmandu. [5]

    Concept Description ------ struct Employee Defines the structure with 4 members emp[100] Array of structure to store multiple employees strcmp() Compares Address string with "Kathmandu" (returns 0 if equal) Age = 40 && Age <= 50 Checks i...

  9. 95 marksPointers as Function ArgumentsAnswer

    List any one advantage and disadvantage of the pointer. How do you pass pointers as function arguments? [5]

    Returning more than one value from a function: A pointer allows a called function to directly modify the original variable in the calling function. This means a single function call can effectively return multiple modified values, which ...

  10. 105 marksInput Output Operations in FileAnswer

    Suppose a file named 'Num.txt' contains a list of integers. Write a program to extract the prime numbers only from that file and write them on 'Prime.txt' file. [5]

    • Read integers from Num.txt using fscanf() - Check each integer for primality using a loop - Write prime numbers to Prime.txt using fprintf() - Use FILE pointer and formatted I/O --- --- Step Description ------------------- fopen("Num.t...
  11. 115 marksUnionAnswer

    What is the advantage of the union over structure? List any four string library functions with the prototype. [5]

    The primary advantage of union over structure is memory efficiency. In a structure, each member is allocated its own separate memory space, so the total memory used is the sum of all members' sizes. In a union, all members share the same...

  12. 125 marksLocal and Global VariableAnswer

    Write short notes on: a. Local, Global, and Static variables b. Conditional Operator [5]

    --- Variables that are defined within the body of a function or a block are called local variables. Key characteristics: - Can be used only within the function or block in which they are declared - They are not accessible outside that fu...