Tribhuwan University

Institute of Science and Technology

Model

Bachelor Level / First Year / First Semester / Science

Bachelors in Information Technology (BIT102)

(C Programming)

Full Marks: 60

Pass Marks: 24

Time: 3 Hours

Candidates are required to give their answers in their own words as for as practicable.

The figures in the margin indicate full marks.

Section A

Long Answers Questions

Attempt any TWO questions.
[2*10=20]
1.
Define array. Differentiate between 1D and 2D array.Write a program that stores 100 integers in an array and display them in ascending order.[4+6]

Define Array. Differentiate between 1D and 2D Array

Array is a collection of elements of the same data type stored in contiguous memory locations, accessed using a common name and an index.

Difference between 1D and 2D Array

Feature 1D Array 2D Array
Structure Linear (single row) Tabular (rows and columns)
Declaration int a[5]; int a[3][4];
Access Single index: a[i] Two indices: a[i][j]
Memory Total size = n×sizeof(datatype)n \times \text{sizeof(datatype)} Total size = m×n×sizeof(datatype)m \times n \times \text{sizeof(datatype)}
Representation Like a list Like a matrix/table

: Program to store 100 integers and display in ascending order

This program uses an array to store 100 integers and Bubble Sort algorithm to arrange them in ascending order before displaying.

#include <stdio.h>

int main() {
    int arr[100], i, j, temp;

    // Input 100 integers
    printf("Enter 100 integers:\n");
    for (i = 0; i < 100; i++) {
        scanf("%d", &arr[i]);
    }

    // Bubble Sort - Ascending Order
    for (i = 0; i < 99; i++) {
        for (j = 0; j < 99 - i; j++) {
            if (arr[j] > arr[j + 1]) {
                temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }

    // Display sorted array
    printf("Array in ascending order:\n");
    for (i = 0; i < 100; i++) {
        printf("%d ", arr[i]);
    }

    return 0;
}

Explanation:

  • Input phase: A for loop reads 100 integers from the user into the array.
  • Sorting phase: Bubble Sort compares adjacent elements and swaps them if they are in the wrong order. The outer loop runs 99 times, and the inner loop reduces comparisons each pass.
  • Output phase: The sorted array is printed in ascending order.

Conclusion: Bubble Sort has a time complexity of O(n2)O(n^2), which is simple to implement for sorting array elements in ascending order.

2.
Define structure. Write syntax for defining and initializing structure?Write a program that stores details of N employees (E_id, E_Name, Salary), and display the details of those employees whose salary is less than 10000.[5+5]
3.
Discuss the advantages of using functions in programming. Differentiate between recursive function and normal function.Write a program using call by reference to swap the values of two variables.[6+4]
Section B

Short Answers Questions

Attempt any Eight questions.
[8*5=40]
4.
Define the basic structure of C program. Explain the Compilation and Execution of a C program? [5]
5.
What are the uses of comments and escape sequences in a C program, explain with example? [5]
6.
What are relational operators and arithmetic operators? Write a C code to check if a given number is odd or even. [5]
7.
Define iterative statements. Write a program that using a loop to compute and prints the sum of squares of first 10 even natural numbers. [5]
8.
How is string defined in C program? Write a program to check if a given string is a palindrome or not. [5]
9.
Differentiate between switch case and else .. if ladder. Why is break statement used inside switch case? Explain briefly. [5]
10.
Describe the concept of pointer and its arithmetic with suitable examples. [5]
11.
Explain the syntax of fwrite() function. Write a program to create a file named "student.txt" and stores record of any five students given by user. [5]
12.
Write short notes on: i) Formatted input/output Write short notes on: ii) C Preprocessors/directives [2.5+2.5]