Semester
Subject
Year
Tribhuwan University
Model
Bachelor Level / First Year / First Semester / Science
(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.
Long Answers Questions
Array is a collection of elements of the same data type stored in contiguous memory locations, accessed using a common name and an index.
| 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 = | Total size = |
| Representation | Like a list | Like a matrix/table |
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:
for loop reads 100 integers from the user into the array.Conclusion: Bubble Sort has a time complexity of , which is simple to implement for sorting array elements in ascending order.
Short Answers Questions