Two-Dimensional Arrays in C: Concepts, Declaration, and Initialization

A one-dimensional array (covered in Post 3) is a single row of values. A two-dimensional array extends this into a grid — rows and columns — perfect for representing matrices, tables, and grids. This is Post 4 of the Unit II series. Declaration and Initialization int matrix[3][4]; // 3 rows, 4 columns — 12 ints … Read more

One-Dimensional Arrays in C: Concepts, Declaration, and Initialization

So far, every variable we’ve used has held exactly one value. An array lets you store multiple values of the same type under a single name, accessed by position. This is Post 3 of the Unit II series — Post 2 covered break, continue, and goto. Why Arrays? Imagine storing the marks of 50 students. … Read more

Sort an Array in Ascending Order Using Bubble Sort in C

This program sorts the elements of a 1-D array in ascending order using the bubble sort technique. C Program #include <stdio.h> int main() { int arr[100], n, i, j, temp; printf(“Enter number of elements: “); scanf(“%d”, &n); printf(“Enter %d elements:\n”, n); for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } for (i ... Read more

Find the Second Largest Element in a 1-D Array Without Sorting in C

This program finds the second largest element in a 1-D array in a single pass, without sorting the array. C Program #include <stdio.h> #include <limits.h> int main() { int arr[100], n, i; int largest = INT_MIN, second = INT_MIN; printf(“Enter number of elements: “); scanf(“%d”, &n); printf(“Enter %d elements:\n”, n); for (i = 0; i … Read more

Find the Largest and Smallest Elements in a 1-D Array in C

This program finds the largest and smallest elements in a one-dimensional array by scanning through it once and keeping track of the current maximum and minimum. C Program #include <stdio.h> int main() { int n, i; int arr[100]; printf(“Enter number of elements: “); scanf(“%d”, &n); printf(“Enter %d elements: “, n); for (i = 0; i … Read more