Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Arrays in C Programming: A Comprehensive Guide with Examples and Quizzes - Prof. sirohi, Lecture notes of Computer Science

A comprehensive introduction to arrays in c programming, covering fundamental concepts, types of arrays, declaration, initialization, accessing elements, sorting, searching, and matrix operations. It includes illustrative examples, program code snippets, and a quiz to test understanding. Suitable for beginners and those seeking to solidify their understanding of arrays in c.

Typology: Lecture notes

2024/2025

Available from 12/11/2024

anuj-sirohi-1
anuj-sirohi-1 🇮🇳

3 documents

1 / 66

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ARRAY
12/11/2024
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42

Partial preview of the text

Download Arrays in C Programming: A Comprehensive Guide with Examples and Quizzes - Prof. sirohi and more Lecture notes Computer Science in PDF only on Docsity!

ARRAY

Topics

• Array

• One Dimensional Array

• Two Dimensional Array

• Three Dimensional Array

• Sorting

• Searching

Arrays Introduction

• Collection of similar type of data

• Derived data type

• Elements of arrays are stored at contiguous

memory locations

Types of Arrays

• One Dimensional

• Multi Dimensional

• Two Dimensional

• Three Dimensional

One Dimensional Arrays Initialization

Initialization:

int a[10]={1,2,3,4,5,6,7,8,9,10};

Position number of the element within array a a[6]

a[0] a[1] a[2] a[3] a[9] a[8] a[7] a[5] a[4] Array Name

Program to read and display n numbers

using array

#include<stdio.h> #include<conio.h> void main() { int a[20],n,i; printf(“Enter the number of elements:\n”); scanf(“%d”,&n); printf(“Enter the elements of array:\n”); for(i=0;i<n;i++) { scanf(“%d”,&a[i]); } printf(“The elements of array are:\n”); for(i=0;i<n;i++) { printf(“%d”,a[i]); } getch(); } Output: Enter the number of elements 5 Enter the elements of array: 5 4 6 27 15 The elements of array are: 5 4 6 27 15

Memory Representation of 2-D Array Position number of the element within array a a[1][1]

a[0][0] a[0][1] a[0][2] a[0][3] a[1][4] a[1][3] a[1][2] a[1][0] a[0][4] Array Name

Two Dimensional Arrays Initialization

Initialization:

int a[2][5]={{0,1,2,3,4},{5,6,7,8,9}};

Position number of the element within array a a[1][1]

a[0][0] a[0][1] a[0][2] a[0][3] a[1][4] a[1][3] a[1][2] a[1][0] a[0][4] Array Name

Sorting

Sorting

• Arranging the elements of array in ascending

or descending order

An Animated Example

a[0] a[1] a[2] a[3] a[4] a[5]

if(a[0]>a[1]) True

An Animated Example

a[0] a[1] a[2] a[3] a[4] a[5]

if(a[0]>a[1]) True

Swap

An Animated Example

a[0] a[1] a[2] a[3] a[4] a[5]

if(a[0]>a[3]) True

An Animated Example

a[0] a[1] a[2] a[3] a[4] a[5]

if(a[0]>a[3]) True

Swap