Array in C Programming – Complete Notes with Examples, Lecture notes of Computer Programming

This document provides complete notes on Arrays in C Programming, including array concepts, declaration, initialization, element access, and practical applications. It contains 10 solved programming problems with source code, sample inputs, and outputs. Topics covered include sorting, reversing arrays, finding maximum and minimum values, insertion, duplicate removal, intersection, union, difference, and summation of array elements. This resource is useful for Structured Programming, C Programming, exam preparation, assignments, and Computer Science students. Keywords: Array, C Programming, Structured Programming, Computer Science, Solved Programs, Data Structure, Programming Notes, Exam Preparation.

Typology: Lecture notes

2025/2026

Available from 06/04/2026

romana-munni
romana-munni 🇧🇩

2 documents

1 / 25

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Array
IN C
C
smart note
better future
notes
on
Easy to
understand
clear
explanation
Important
points
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19

Partial preview of the text

Download Array in C Programming – Complete Notes with Examples and more Lecture notes Computer Programming in PDF only on Docsity!

Array

IN C

C

smart note

better future

notes

on

Easyto

understand

clear

explanation

Important

points

ARRAYS A regular variable stores a single data An array stores multiple data of similar type Each data in an array is accessed by an index ( Starts from 0)

ARRAY DECLARATION []; Example: float cgpa[100]; ARRAY ELEMENT ACCESS Index 0 1 2 3 4 5 6 7 8 9 Data 4.0 3.9 3.7 3.8 3.8 3.2 2.9 3.9 3.5 3. float cgpa[10]; cgpa[0] = 4.0; scanf(“%f”, &cgpa[2]); printf(“%f\n”, cgpa[4] // output is 3.

#include int main() { int a[10000]; int sum = 0, i; for(i = 0; i < 10000; i++) scanf("%d", &a[i]); for(i = 0; i < 10000; i++) sum += a[i]; printf("The sum is %d\n", sum); return 0; }

1 .. WAP that will take n integers into an array A.

Now sort them in ascending order within that

array. Finally show all elements of array A.

#include int main() { int n, i, j, temp; scanf("%d", &n); int A[n]; for(i = 0; i < n; i++) { scanf("%d", &A[i]); } for(i = 0; i < n - 1; i++) { for(j = 0; j < n - i - 1; j++) { if(A[j] > A[j + 1]) { temp = A[j];

A[j] = A[j + 1]; A[j + 1] = temp; } } } for(i = 0; i < n; i++) { printf("%d\n", A[i]); } return 0; } 8 7 8 1 3 2 6 4 3 1 2 3 3 4 6 7 8 Input OUTPUT

arr[n - 1 - i] = temp;

for(i = 0; i < n; i++)

printf("%d ", arr[i]);

return 0;

5 1 2 3 4 5 5 4 3 2 1 Input output

3 .WAP that will take n integer numbers into an array, and then find the maximum -minimum among them with its index position. #include int main() { int n, i; scanf("%d", &n); int arr[n]; for(i = 0; i < n; i++) { scanf("%d", &arr[i]); } int max = arr[0], min = arr[0]; int maxIndex = 0, minIndex = 0; for(i = 1; i < n; i++) { if(arr[i] > max) { max = arr[i]; maxIndex = i;

4 WAP that will take n integer numbers as input in an array and then insert a number in a position specified by the user in the array. #include int main() { int n, i, pos, num; scanf("%d", &n); int arr[n + 1]; for(i = 0; i < n; i++) { scanf("%d", &arr[i]); } scanf("%d", &pos); scanf("%d", &num); for(i = n; i > pos; i--) { arr[i] = arr[i - 1]; }

arr[pos] = num; for(i = 0; i <= n; i++) { printf("%d ", arr[i]); } return 0; } 5 10 20 30 40 50 2 25 10 20 25 30 40 50 Input Output

A[i] = B[i];

B[i] = temp;

printf("Array A:\n");

for(i = 0; i < n; i++)

printf("%d ", A[i]);

printf("\nArray B:\n");

for(i = 0; i < n; i++)

printf("%d ", B[i]);

return 0;

Input output 5 1 2 3 4 5 6 7 8 9 10

Array A:

Array B:

6 WAP that will take n integers into an array A.

Now remove all duplicates numbers from that array.

#include int main() { int n, i, j, k; scanf("%d", &n); int A[n]; for(i = 0; i < n; i++) { scanf("%d", &A[i]); } for(i = 0; i < n; i++) { for(j = i + 1; j < n; ) { if(A[i] == A[j]) { for(k = j; k < n - 1; k++) { A[k] = A[k + 1]; }

7 WAP that will take n integers into array A and m positive integers into array B. Now find the intersection (set operation) of array A and B. #include int main() { int n, m, i, j; scanf("%d", &n); int A[n]; for(i = 0; i < n; i++) { scanf("%d", &A[i]); } scanf("%d", &m); int B[m]; for(i = 0; i < m; i++) { scanf("%d", &B[i]); } for(i = 0; i < n; i++) { for(j = 0; j < m; j++)

scanf("%d", &B[i]);

for(i = 0; i < n; i++)

for(j = 0; j < m; j++)

if(A[i] == B[j])

printf("%d ", A[i]);

break;

return 0;

Input Output 5 1 2 3 4 5 4 3 4 6 7 3 4