SlideShare a Scribd company logo
1 of 36
Download to read offline
2/6/2021
Dharma Kumari Kalakheti 1
2/6/2021
Dharma Kumari Kalakheti 2
➢ Array is a collection of same type elements under
the same variable identifier referenced by index
number.
➢ It supports the homogeneous data type not
heterogeneous.
➢ Arrays are widely used within programming for
different purposes such as sorting, searching and
etc.
➢ Arrays are efficient and useful for performing
operations .
2/6/2021
Dharma Kumari Kalakheti 3
Group of elements storing a common type of data
int number[5] ={ };
Data type
array name
size
Elements differentiated by their positions
in the array
value
2/6/2021
Dharma Kumari Kalakheti 4
➢ It always start from 0 (zero) position and end
with size -1.
➢ eg. int a[5]={21,23,14,15,22}
➢ Therefore in an array with “n” elements first
index is “0” and the last index is “n-1”.
➢ The value of each element of the array is listed
within two curly brackets ({ }) and a comma (,)
is used to separate one value from another.
2/6/2021
Dharma Kumari Kalakheti
21 23 14 15 22
0 1 2 3 4
5
➢ Array name must not be separate form the square
brackets containing the index.
data-type array-name[array-size]={define variable};
int a[5]={11,12,13,14,15} // right declaration.
BUT
int a [5] ={11,12,13,14,15} // wrong declaration.
2/6/2021
Dharma Kumari Kalakheti 6
index[0] = 11 index[1] = 12 index[2] = 13
index[3] =14 index[4] = 15
int digits[5]={11,12,13,14,15};
2/6/2021
Dharma Kumari Kalakheti 7
#include<stdio.h>
#include<conio.h> header file
void main() main function start
{
int a[5]={12,13,14,15,16},i;
printf("this is input result n");
for(i=0;i<5;i++) main program
printf("n %d",a[i]);
getch();
}
This is input result
12
13 Output result
14
15
16
12 13 14 15 16
0 1 2 3 4
2/6/2021
Dharma Kumari Kalakheti 8
 One-dimensional arrays
 Multidimensional array
➢ The type of arrays that we discussed up to now is
called a one dimensional array.
Single dimensional array is an array with a variable
with single subscript.
 Declaration of one-dimensional array
data_type array_name[array_size];
For example: int age[5];
2/6/2021
Dharma Kumari Kalakheti 9
Here, the name of array is age. The size of
array is 5,i.e., there are 5 items(elements)
of array age. All element in an array are
of the same type (int, in this case).
2/6/2021
Dharma Kumari Kalakheti
int age[5];
10
2/6/2021
Dharma Kumari Kalakheti
/* example of an array */
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
int n[5]= {2, 4, 6, 3, 0};
for (i=0; i<=4; i++)
{
printf("%dn", n[i]);
}
getch();
} 11
Output:
/* example to input marks of 5 students and to display them */
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
int n[5];
for (i=1; i<=5; i++)
{
printf("enter the marks:");
scanf("%d", &n[i]);
}
for (i=1; i<=5; i++)
{
printf("%dn", n[i]);
}
getch();
}
2/6/2021 Dharma Kumari Kalakheti 12
Sample Program 2
3. Write a flowchart and a program to read 5 persons age maximum,
minimum
#include <stdio.h>
#include <conio.h>
void main()
{
int age[5],max=0,min=100,i;
clrscr();
for (i=1;i<=5;i++)
{
printf("enter the age: ");
scanf("%d",&age[i]);
if (age[i]>max)
max=age[i];
if(age[i]<min)
min=age[i];
}
printf("nmax=%d", max);
printf("nmin=%d",min);
getch();
}
WAP to interchange given numbers
{3,61,80,9,70,51,2,1}
#include <stdio.h>
#include <conio.h> //interchange the number
void main()
{
int num[8]={3,61,80,9,70,51,2,1};
int i,temp;
clrscr();
for(i=0;i<=7;i+=2)
{
temp=num[i];
num[i]=num[i+1];
num[i+1]=temp;
}
for(i=0;i<=7;i++)
printf("n marks=%d",num[i]);
getch();
}
2/6/2021 Dharma Kumari Kalakheti 15
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int arr[5]={25,17,31,13,2},i,j,temp;
for(i=0;i<5;i++)
{
for(j=0; j<5-i; j++)
{
if (arr[j]> arr[j+1])
{
temp=arr[j+1];
arr[j+1]= arr[j];
arr[j]=temp; }
}
}
printf("nnarray after sorting n");
for(j=0;j<5;j++)
printf("%dt",arr[j]);
getch();
}
//Program to sort following numbere
in Ascending order= 25,17,31,13,2
#include<stdio.h>
#include<conio.h>
int fact(int n);
void main()
{
int n;
clrscr();
printf("Enter any Num");
scanf("%d",&n);
printf("fact=%d",fact(n));
getch();
}
int fact(int n)
{
if(n<=1)
return(1);
else
return(n*fact(n-1));
}
/*WAP to find the factorial of a number using recursive function*/
2/6/2021 Dharma Kumari Kalakheti 17
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int arr[5],i,j,temp;
printf("enter any numbers:");
for(i=0;i<5;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<5;i++)
{
for(j=0; j<5-i; j++)
{
if (arr[j]> arr[j+1])
{
temp=arr[j];
arr[j]= arr[j+1];
arr[j+1]=temp;
}
}
}
printf("nnarray after sorting n");
for(j=0;j<5;j++)
printf("%dt",arr[j]);
getch();
}
WAP to enter the 5 number and sorting in
ascending order
2/6/2021 Dharma Kumari Kalakheti 18
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int n[5],i,j,temp;
printf("enter any numbers:");
for(i=0;i<5;i++)
{
scanf("%d",&n[i]);
}
for(i=0;i<5;i++)
{
for(j=0; j<5-i; j++)
{
if (n[j]> n[j+1])
{
temp=n[j];
n[j]= n[j+1];
n[j+1]=temp;} } }
printf("nnarray after sorting n");
for(j=0;j<5;j++)
printf("%dt",n[j]);
getch();
}
2/6/2021 Dharma Kumari Kalakheti 19
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int arr[5]={25,17,31,13,12},i,j,temp;
for(i=0;i<5;i++)
{
for(j=0; j<5-i; j++)
{
if (arr[j]> arr[j+1])
{
temp=arr[j];
arr[j]= arr[j+1];
arr[j+1]=temp;
}
}
}
printf("nnarray after sorting n");
for(j=0;j<5;j++)
printf("%dt",arr[j]);
getch();
}
//Program to sort following numbere in
decending order= 25,17,31,13,2
#include<stdio.h>
#include<conio.h>
void num();
void main()
{
clrscr();
num();
getch();
}
void num()
{
clrscr();
int arr[5]={25,17,31,13,12},i,j,temp;
for(i=0;i<5;i++)
{
for(j=0; j<5-i; j++)
{
if (arr[j]> arr[j+1])
{
temp=arr[j];
arr[j]= arr[j+1];
arr[j+1]=temp;
}
}
}
printf("nnarray after sorting n");
for(j=0;j<5;j++)
printf("%dt",arr[j]);
}
WAP to enter the 10 number and sorting in
ascending order using function
7. WAP to print the odd and even numbers from 1 to 10 and
sum them separately.
#include <stdio.h>
#include <conio.h>
void main()
{
int a[10]={1,2,3,4,5},sum=0,even=0,odd=0,i;
for(i=0;i<=4;i++)
{
//printf("enter the number=");
//scanf("%d",&a[i]);
sum=sum+a[i];
if (a[i]%2==0)
{
even=even+a[i];
}
else
odd=odd+a[i];
}
printf("ntotal sum=%d",sum);
printf("ntotal even=%d",even);
printf("ntotal odd=%d",odd);
getch();
}
2/6/2021 Dharma Kumari Kalakheti 22
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int arr[5]={25,17,31,13,12},i,j,temp;
for(i=0;i<5;i++)
{
for(j=0; j<5-i; j++)
{
if (arr[j]<arr[j+1])
{
temp=arr[j+1];
arr[j+1]= arr[j];
arr[j]=temp;
}
}
}
printf("nnarray after sorting n");
for(j=1;j<=5;j++)
printf("%dt",arr[j]);
getch();
}
/* Write a program to read five persons age using array and find out
average age. (preeboard exam 2070*/
2/6/2021 Dharma Kumari Kalakheti 23
#include <stdio.h>
#include <conio.h>
void main()
{
int age[5],sum=0,avg,i;
clrscr();
for(i=0;i<5;i++)
{
printf("Enter five persons age:");
scanf("%d",&age[i]);
sum= sum+age[i];
}
avg=sum/5;
//printf("nsum=%d",sum);
printf("navg=%d",avg);
getch();
}
Print “NEPAL”
#include <stdio.h >
#include <conio.h>
void main()
{
char n[5]= "NEPAL",i;
for(i=0;i<5;i++)
{
printf("%c",n[i]);
}
getch();
}
2/6/2021 Dharma Kumari Kalakheti 24
Show this (2072-3-18)
N
N E
N E P
N E P A
N E P A L
#include <stdio.h >
#include <conio.h>
void main()
{
char n[6]= "NEPAL",i,j;
for(i=0;i<=5;i++)
{
for(j=0;j<i;j++)
{
printf("t%c",n[j]);
}
printf("n");
}
getch();
Show this
NEPAL
NEPA
NEP
NE
N
#include <stdio.h >
#include <conio.h>
void main()
{
char n[6]= "NEPAL",i,j;
for(i=5;i>1;i--)
{
for(j=0;j<i;j++)
{
printf("t%c",n[j]);
}
printf("n");
}
getch();
}
Multi- dimensional arrays are those which have more then one
dimensions. Multi- dimensional arrays are defined in much the
same manner as one dimensional array, except that a separate
pair of square brackets is required for each subscript .thus ,two
dimensional arrays will require two pairs of square brackets.
In 2-D array, the first dimensional specifies number of rows and
second specifies columns. Each row contains elements of many
columns. Thus ,a row is 1-D array .2-D array contains multiple
rows .Thus, 2-D array is an array of 1-D arrays. As each row will
contain elements of many columns, 2-D array is an array with a
variable with two subscripts e.g
Int a[2] [2]
This matrix can be represented by double
dimensional array
Int a [2] [2] where
A [0] [0]=2
A [0] [1]=3
A [1] [0]=1
A [1] [1]=4
We can represent matrix in double dimensional
array 2 3
1 4
Syntax:-
data_type array_name[expression 1][expression 2]…[expression n] ;
int no[3][3] ;
Defining 2 dimensional array
0 1 2
1
2
2/6/2021 Dharma Kumari Kalakheti 29
2/6/2021 Dharma Kumari Kalakheti 30
#include <stdio.h>
#include <conio.h>
void main() // print the 2/2 matrix
{
int A[2][2],i,j;
for (i=0;i<2;i++)
for(j=0;j<2;j++)
//this is a main matrix entry
{
printf("enter the element %d %d:", i, j);
scanf("%d",&A[i][j]);
}
//print matrix
printf("this is my first matrix: ");
for (i=0;i<2;i++)
{
printf("n");
for(j=0;j<2;j++)
{
printf("%dt",A[i][j]);
}
printf("n");
}
getch();
}
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int a[2][2],i,j;
printf("enter the matrix:n");
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
scanf("%d",&a[i][j]);
}
printf("the matrix you supplied");
for(i=1;i<=2;i++)
{
printf("n");
for(j=1;j<=2;j++)
printf("t%d",a[i][j]);
}
printf("n");
printf("transpose of the matrixn");
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
printf("%dt",a[j][i]);
}
printf("n");
}
getch();
}
#include <stdio.h>
#include <conio.h>
void main()
{
int A[2][2],i,j;
for (i=0;i<2;i++)
for(j=0;j<2;j++)
//this is a main matrix entry
{
printf("enter the element %d %d:", i,j);
scanf("%d",&A[i][j]);
}
//print matrix
printf("this is 2/2 matrix: ");
for (i=0;i<2;i++)
{
printf("n");
for(j=0;j<2;j++)
{
printf("%dt",A[i][j]);
}
printf("n");
}
printf("transpose of the matrixn");
for(i=0;i<2;i++)
{
printf("n");
for(j=0;j<2;j++)
{
printf("%dt",A[j][i]);
}
printf("n");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int no[3][3],i,j;
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
{
printf("enter the number %d = ",i,j);
scanf("%d",&no[i][j]);
}
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf("t %d",no[i][j]);
}
printf("n");
}
getch();
} 2/6/2021
Dharma Kumari Kalakheti 33
Enter the number 1
1
0
1
Enter the number 2
1
1
1
Enter the number 3
1
0
1
The result is :-
1 0 1
1 1 1
1 0 1
2/6/2021
Dharma Kumari Kalakheti 34
2/6/2021 Dharma Kumari Kalakheti 35
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[3][3], i, j, sum=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("nEnter the value for
A[%d][%d]:",i,j);
scanf("%d",&arr[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
sum=sum+arr[i][j];
}
}
/*Display the value of sum*/
printf("nThe sum of the elements of 2-D
array is %d", sum);
getch();
}
Program that accept values in 2-Dimensional
3 by 3 array and displays the sum of all the
elements.
2/6/2021
Dharma Kumari Kalakheti
36

More Related Content

What's hot (20)

Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Arrays in Java | Edureka
Arrays in Java | EdurekaArrays in Java | Edureka
Arrays in Java | Edureka
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
 
Arrays in C
Arrays in CArrays in C
Arrays in C
 
Data structures
Data structuresData structures
Data structures
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Arrays
ArraysArrays
Arrays
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
1-D array
1-D array1-D array
1-D array
 
arrays of structures
arrays of structuresarrays of structures
arrays of structures
 
Array assignment
Array assignmentArray assignment
Array assignment
 
Array
ArrayArray
Array
 
Array and Collections in c#
Array and Collections in c#Array and Collections in c#
Array and Collections in c#
 
2 data structure in R
2 data structure in R2 data structure in R
2 data structure in R
 
Array in c#
Array in c#Array in c#
Array in c#
 
Unit 1 LINEAR DATA STRUCTURES
Unit 1  LINEAR DATA STRUCTURESUnit 1  LINEAR DATA STRUCTURES
Unit 1 LINEAR DATA STRUCTURES
 
array
array array
array
 
07slide
07slide07slide
07slide
 
Data Structures (BE)
Data Structures (BE)Data Structures (BE)
Data Structures (BE)
 

Similar to About Array

Similar to About Array (20)

Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
Arrays
ArraysArrays
Arrays
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
unit1Intro_final.pptx
unit1Intro_final.pptxunit1Intro_final.pptx
unit1Intro_final.pptx
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
ARRAYS
ARRAYSARRAYS
ARRAYS
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 

More from DharmaKumariBhandari

More from DharmaKumariBhandari (6)

K map
K map K map
K map
 
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,  De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
 
Loop's definition and practical code in C programming
Loop's definition and  practical code in C programming Loop's definition and  practical code in C programming
Loop's definition and practical code in C programming
 
Pointer
PointerPointer
Pointer
 
C programme presentation
C programme presentationC programme presentation
C programme presentation
 
social prospective in Education
social prospective in Educationsocial prospective in Education
social prospective in Education
 

Recently uploaded

Pokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy TheoryPokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy Theorydrae5
 
CALL ON ➥8923113531 🔝Call Girls Jankipuram Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Jankipuram Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Jankipuram Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Jankipuram Lucknow best sexual serviceanilsa9823
 
call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..nishakur201
 
Lilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxLilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxABMWeaklings
 
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,dollysharma2066
 
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...anilsa9823
 
LC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfLC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfpastor83
 
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual serviceanilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female serviceanilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual serviceanilsa9823
 
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girlsPooja Nehwal
 
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morcall Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morvikas rana
 
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...PsychicRuben LoveSpells
 
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)Delhi Call girls
 
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)Delhi Call girls
 
Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666nishakur201
 
The Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushThe Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushShivain97
 

Recently uploaded (20)

(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
 
Pokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy TheoryPokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy Theory
 
CALL ON ➥8923113531 🔝Call Girls Jankipuram Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Jankipuram Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Jankipuram Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Jankipuram Lucknow best sexual service
 
call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..
 
Lilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxLilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptx
 
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
 
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
 
LC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfLC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdf
 
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
 
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
 
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
 
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
 
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morcall Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
 
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
 
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
 
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
 
Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666
 
The Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushThe Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by Mindbrush
 
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
 

About Array

  • 3. ➢ Array is a collection of same type elements under the same variable identifier referenced by index number. ➢ It supports the homogeneous data type not heterogeneous. ➢ Arrays are widely used within programming for different purposes such as sorting, searching and etc. ➢ Arrays are efficient and useful for performing operations . 2/6/2021 Dharma Kumari Kalakheti 3
  • 4. Group of elements storing a common type of data int number[5] ={ }; Data type array name size Elements differentiated by their positions in the array value 2/6/2021 Dharma Kumari Kalakheti 4
  • 5. ➢ It always start from 0 (zero) position and end with size -1. ➢ eg. int a[5]={21,23,14,15,22} ➢ Therefore in an array with “n” elements first index is “0” and the last index is “n-1”. ➢ The value of each element of the array is listed within two curly brackets ({ }) and a comma (,) is used to separate one value from another. 2/6/2021 Dharma Kumari Kalakheti 21 23 14 15 22 0 1 2 3 4 5
  • 6. ➢ Array name must not be separate form the square brackets containing the index. data-type array-name[array-size]={define variable}; int a[5]={11,12,13,14,15} // right declaration. BUT int a [5] ={11,12,13,14,15} // wrong declaration. 2/6/2021 Dharma Kumari Kalakheti 6
  • 7. index[0] = 11 index[1] = 12 index[2] = 13 index[3] =14 index[4] = 15 int digits[5]={11,12,13,14,15}; 2/6/2021 Dharma Kumari Kalakheti 7
  • 8. #include<stdio.h> #include<conio.h> header file void main() main function start { int a[5]={12,13,14,15,16},i; printf("this is input result n"); for(i=0;i<5;i++) main program printf("n %d",a[i]); getch(); } This is input result 12 13 Output result 14 15 16 12 13 14 15 16 0 1 2 3 4 2/6/2021 Dharma Kumari Kalakheti 8
  • 9.  One-dimensional arrays  Multidimensional array ➢ The type of arrays that we discussed up to now is called a one dimensional array. Single dimensional array is an array with a variable with single subscript.  Declaration of one-dimensional array data_type array_name[array_size]; For example: int age[5]; 2/6/2021 Dharma Kumari Kalakheti 9
  • 10. Here, the name of array is age. The size of array is 5,i.e., there are 5 items(elements) of array age. All element in an array are of the same type (int, in this case). 2/6/2021 Dharma Kumari Kalakheti int age[5]; 10
  • 11. 2/6/2021 Dharma Kumari Kalakheti /* example of an array */ #include<stdio.h> #include<conio.h> void main() { int i; int n[5]= {2, 4, 6, 3, 0}; for (i=0; i<=4; i++) { printf("%dn", n[i]); } getch(); } 11 Output:
  • 12. /* example to input marks of 5 students and to display them */ #include<stdio.h> #include<conio.h> void main() { int i; int n[5]; for (i=1; i<=5; i++) { printf("enter the marks:"); scanf("%d", &n[i]); } for (i=1; i<=5; i++) { printf("%dn", n[i]); } getch(); } 2/6/2021 Dharma Kumari Kalakheti 12 Sample Program 2
  • 13. 3. Write a flowchart and a program to read 5 persons age maximum, minimum #include <stdio.h> #include <conio.h> void main() { int age[5],max=0,min=100,i; clrscr(); for (i=1;i<=5;i++) { printf("enter the age: "); scanf("%d",&age[i]); if (age[i]>max) max=age[i]; if(age[i]<min) min=age[i]; } printf("nmax=%d", max); printf("nmin=%d",min); getch(); }
  • 14. WAP to interchange given numbers {3,61,80,9,70,51,2,1} #include <stdio.h> #include <conio.h> //interchange the number void main() { int num[8]={3,61,80,9,70,51,2,1}; int i,temp; clrscr(); for(i=0;i<=7;i+=2) { temp=num[i]; num[i]=num[i+1]; num[i+1]=temp; } for(i=0;i<=7;i++) printf("n marks=%d",num[i]); getch(); }
  • 15. 2/6/2021 Dharma Kumari Kalakheti 15 #include <stdio.h> #include <conio.h> void main() { clrscr(); int arr[5]={25,17,31,13,2},i,j,temp; for(i=0;i<5;i++) { for(j=0; j<5-i; j++) { if (arr[j]> arr[j+1]) { temp=arr[j+1]; arr[j+1]= arr[j]; arr[j]=temp; } } } printf("nnarray after sorting n"); for(j=0;j<5;j++) printf("%dt",arr[j]); getch(); } //Program to sort following numbere in Ascending order= 25,17,31,13,2
  • 16. #include<stdio.h> #include<conio.h> int fact(int n); void main() { int n; clrscr(); printf("Enter any Num"); scanf("%d",&n); printf("fact=%d",fact(n)); getch(); } int fact(int n) { if(n<=1) return(1); else return(n*fact(n-1)); } /*WAP to find the factorial of a number using recursive function*/
  • 17. 2/6/2021 Dharma Kumari Kalakheti 17 #include <stdio.h> #include <conio.h> void main() { clrscr(); int arr[5],i,j,temp; printf("enter any numbers:"); for(i=0;i<5;i++) { scanf("%d",&arr[i]); } for(i=0;i<5;i++) { for(j=0; j<5-i; j++) { if (arr[j]> arr[j+1]) { temp=arr[j]; arr[j]= arr[j+1]; arr[j+1]=temp; } } } printf("nnarray after sorting n"); for(j=0;j<5;j++) printf("%dt",arr[j]); getch(); } WAP to enter the 5 number and sorting in ascending order
  • 18. 2/6/2021 Dharma Kumari Kalakheti 18 #include <stdio.h> #include <conio.h> void main() { clrscr(); int n[5],i,j,temp; printf("enter any numbers:"); for(i=0;i<5;i++) { scanf("%d",&n[i]); } for(i=0;i<5;i++) { for(j=0; j<5-i; j++) { if (n[j]> n[j+1]) { temp=n[j]; n[j]= n[j+1]; n[j+1]=temp;} } } printf("nnarray after sorting n"); for(j=0;j<5;j++) printf("%dt",n[j]); getch(); }
  • 19. 2/6/2021 Dharma Kumari Kalakheti 19 #include <stdio.h> #include <conio.h> void main() { clrscr(); int arr[5]={25,17,31,13,12},i,j,temp; for(i=0;i<5;i++) { for(j=0; j<5-i; j++) { if (arr[j]> arr[j+1]) { temp=arr[j]; arr[j]= arr[j+1]; arr[j+1]=temp; } } } printf("nnarray after sorting n"); for(j=0;j<5;j++) printf("%dt",arr[j]); getch(); } //Program to sort following numbere in decending order= 25,17,31,13,2
  • 20. #include<stdio.h> #include<conio.h> void num(); void main() { clrscr(); num(); getch(); } void num() { clrscr(); int arr[5]={25,17,31,13,12},i,j,temp; for(i=0;i<5;i++) { for(j=0; j<5-i; j++) { if (arr[j]> arr[j+1]) { temp=arr[j]; arr[j]= arr[j+1]; arr[j+1]=temp; } } } printf("nnarray after sorting n"); for(j=0;j<5;j++) printf("%dt",arr[j]); } WAP to enter the 10 number and sorting in ascending order using function
  • 21. 7. WAP to print the odd and even numbers from 1 to 10 and sum them separately. #include <stdio.h> #include <conio.h> void main() { int a[10]={1,2,3,4,5},sum=0,even=0,odd=0,i; for(i=0;i<=4;i++) { //printf("enter the number="); //scanf("%d",&a[i]); sum=sum+a[i]; if (a[i]%2==0) { even=even+a[i]; } else odd=odd+a[i]; } printf("ntotal sum=%d",sum); printf("ntotal even=%d",even); printf("ntotal odd=%d",odd); getch(); }
  • 22. 2/6/2021 Dharma Kumari Kalakheti 22 #include <stdio.h> #include <conio.h> void main() { clrscr(); int arr[5]={25,17,31,13,12},i,j,temp; for(i=0;i<5;i++) { for(j=0; j<5-i; j++) { if (arr[j]<arr[j+1]) { temp=arr[j+1]; arr[j+1]= arr[j]; arr[j]=temp; } } } printf("nnarray after sorting n"); for(j=1;j<=5;j++) printf("%dt",arr[j]); getch(); }
  • 23. /* Write a program to read five persons age using array and find out average age. (preeboard exam 2070*/ 2/6/2021 Dharma Kumari Kalakheti 23 #include <stdio.h> #include <conio.h> void main() { int age[5],sum=0,avg,i; clrscr(); for(i=0;i<5;i++) { printf("Enter five persons age:"); scanf("%d",&age[i]); sum= sum+age[i]; } avg=sum/5; //printf("nsum=%d",sum); printf("navg=%d",avg); getch(); }
  • 24. Print “NEPAL” #include <stdio.h > #include <conio.h> void main() { char n[5]= "NEPAL",i; for(i=0;i<5;i++) { printf("%c",n[i]); } getch(); } 2/6/2021 Dharma Kumari Kalakheti 24
  • 25. Show this (2072-3-18) N N E N E P N E P A N E P A L #include <stdio.h > #include <conio.h> void main() { char n[6]= "NEPAL",i,j; for(i=0;i<=5;i++) { for(j=0;j<i;j++) { printf("t%c",n[j]); } printf("n"); } getch();
  • 26. Show this NEPAL NEPA NEP NE N #include <stdio.h > #include <conio.h> void main() { char n[6]= "NEPAL",i,j; for(i=5;i>1;i--) { for(j=0;j<i;j++) { printf("t%c",n[j]); } printf("n"); } getch(); }
  • 27. Multi- dimensional arrays are those which have more then one dimensions. Multi- dimensional arrays are defined in much the same manner as one dimensional array, except that a separate pair of square brackets is required for each subscript .thus ,two dimensional arrays will require two pairs of square brackets. In 2-D array, the first dimensional specifies number of rows and second specifies columns. Each row contains elements of many columns. Thus ,a row is 1-D array .2-D array contains multiple rows .Thus, 2-D array is an array of 1-D arrays. As each row will contain elements of many columns, 2-D array is an array with a variable with two subscripts e.g Int a[2] [2]
  • 28. This matrix can be represented by double dimensional array Int a [2] [2] where A [0] [0]=2 A [0] [1]=3 A [1] [0]=1 A [1] [1]=4 We can represent matrix in double dimensional array 2 3 1 4
  • 29. Syntax:- data_type array_name[expression 1][expression 2]…[expression n] ; int no[3][3] ; Defining 2 dimensional array 0 1 2 1 2 2/6/2021 Dharma Kumari Kalakheti 29
  • 30. 2/6/2021 Dharma Kumari Kalakheti 30 #include <stdio.h> #include <conio.h> void main() // print the 2/2 matrix { int A[2][2],i,j; for (i=0;i<2;i++) for(j=0;j<2;j++) //this is a main matrix entry { printf("enter the element %d %d:", i, j); scanf("%d",&A[i][j]); } //print matrix printf("this is my first matrix: "); for (i=0;i<2;i++) { printf("n"); for(j=0;j<2;j++) { printf("%dt",A[i][j]); } printf("n"); } getch(); }
  • 31. #include <stdio.h> #include <conio.h> void main() { clrscr(); int a[2][2],i,j; printf("enter the matrix:n"); for(i=1;i<=2;i++) { for(j=1;j<=2;j++) scanf("%d",&a[i][j]); } printf("the matrix you supplied"); for(i=1;i<=2;i++) { printf("n"); for(j=1;j<=2;j++) printf("t%d",a[i][j]); } printf("n"); printf("transpose of the matrixn"); for(i=1;i<=2;i++) { for(j=1;j<=2;j++) { printf("%dt",a[j][i]); } printf("n"); } getch(); }
  • 32. #include <stdio.h> #include <conio.h> void main() { int A[2][2],i,j; for (i=0;i<2;i++) for(j=0;j<2;j++) //this is a main matrix entry { printf("enter the element %d %d:", i,j); scanf("%d",&A[i][j]); } //print matrix printf("this is 2/2 matrix: "); for (i=0;i<2;i++) { printf("n"); for(j=0;j<2;j++) { printf("%dt",A[i][j]); } printf("n"); } printf("transpose of the matrixn"); for(i=0;i<2;i++) { printf("n"); for(j=0;j<2;j++) { printf("%dt",A[j][i]); } printf("n"); } getch(); }
  • 33. #include<stdio.h> #include<conio.h> void main() { int no[3][3],i,j; for(i=1;i<=3;i++) for(j=1;j<=3;j++) { printf("enter the number %d = ",i,j); scanf("%d",&no[i][j]); } for(i=1;i<=3;i++) { for(j=1;j<=3;j++) { printf("t %d",no[i][j]); } printf("n"); } getch(); } 2/6/2021 Dharma Kumari Kalakheti 33
  • 34. Enter the number 1 1 0 1 Enter the number 2 1 1 1 Enter the number 3 1 0 1 The result is :- 1 0 1 1 1 1 1 0 1 2/6/2021 Dharma Kumari Kalakheti 34
  • 35. 2/6/2021 Dharma Kumari Kalakheti 35 #include<stdio.h> #include<conio.h> void main() { int arr[3][3], i, j, sum=0; for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("nEnter the value for A[%d][%d]:",i,j); scanf("%d",&arr[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { sum=sum+arr[i][j]; } } /*Display the value of sum*/ printf("nThe sum of the elements of 2-D array is %d", sum); getch(); } Program that accept values in 2-Dimensional 3 by 3 array and displays the sum of all the elements.