SlideShare a Scribd company logo
1 of 36
12/4/2020Dharma Kumari Kalakheti 1
12/4/2020Dharma 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 .
12/4/2020Dharma 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
12/4/2020Dharma 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.
12/4/2020Dharma 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.
12/4/2020Dharma 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};
12/4/2020Dharma 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
12/4/2020Dharma 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];
12/4/2020Dharma 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).
12/4/2020Dharma Kumari Kalakheti
int
age[5];
10
12/4/2020Dharma 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();
}
12/4/2020 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();
}
12/4/2020 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*/
12/4/2020 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
12/4/2020 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();
}
12/4/2020 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();
}
12/4/2020 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*/
12/4/2020 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();
}
12/4/2020 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
12/4/2020 Dharma Kumari Kalakheti 29
12/4/2020 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();
} 12/4/2020Dharma 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
12/4/2020Dharma Kumari Kalakheti 34
12/4/2020 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.
12/4/2020
Dharma Kumari Kalakheti
36

More Related Content

What's hot (20)

Array in c++
Array in c++Array in c++
Array in c++
 
arrays of structures
arrays of structuresarrays of structures
arrays of structures
 
Chapter 9 ds
Chapter 9 dsChapter 9 ds
Chapter 9 ds
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Arrays
ArraysArrays
Arrays
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
Array in c
Array in cArray in c
Array in c
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Data structures
Data structuresData structures
Data structures
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Array in c
Array in cArray in c
Array in c
 
Array
ArrayArray
Array
 
Row major and column major in 2 d
Row major and column major in 2 dRow major and column major in 2 d
Row major and column major in 2 d
 
Array in C
Array in CArray in C
Array in C
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
arrays in c
arrays in carrays in c
arrays in c
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C Language
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 

Similar to Array

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 Appili Vamsi Krishna
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptxSajalFayyaz
 
Array assignment
Array assignmentArray assignment
Array assignmentAhmad Kamal
 
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 arrayimtiazalijoono
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdfHEMAHEMS5
 
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.pptxrohinitalekar1
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functionsSwarup Boro
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programmingnmahi96
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm KristinaBorooah
 
Data structure array
Data structure  arrayData structure  array
Data structure arrayMajidHamidAli
 

Similar to 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
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
 
Array assignment
Array assignmentArray assignment
Array assignment
 
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
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
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
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Data structure array
Data structure  arrayData structure  array
Data structure array
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
C_Arrays.pptx
C_Arrays.pptxC_Arrays.pptx
C_Arrays.pptx
 

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

REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdfREFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdfssusere8ea60
 
办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭o8wvnojp
 
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ EscortsDelhi Escorts Service
 
social media chat application main ppt.pptx
social media chat application main ppt.pptxsocial media chat application main ppt.pptx
social media chat application main ppt.pptxsprasad829829
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证kbdhl05e
 
Powerpoint on Writing a Newspaper Report.pptx
Powerpoint on Writing a Newspaper Report.pptxPowerpoint on Writing a Newspaper Report.pptx
Powerpoint on Writing a Newspaper Report.pptxNeelamMulchandani1
 
E J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxE J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxJackieSparrow3
 
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan
 
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 AvilableCall Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilabledollysharma2066
 
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndCall Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndPooja Nehwal
 
Postal Ballot procedure for employees to utilise
Postal Ballot procedure for employees to utilisePostal Ballot procedure for employees to utilise
Postal Ballot procedure for employees to utiliseccsubcollector
 
Dhule Call Girls #9907093804 Contact Number Escorts Service Dhule
Dhule Call Girls #9907093804 Contact Number Escorts Service DhuleDhule Call Girls #9907093804 Contact Number Escorts Service Dhule
Dhule Call Girls #9907093804 Contact Number Escorts Service Dhulesrsj9000
 
Ahmedabad Escorts Girl Services For Male Tourists 9537192988
Ahmedabad Escorts Girl Services For Male Tourists 9537192988Ahmedabad Escorts Girl Services For Male Tourists 9537192988
Ahmedabad Escorts Girl Services For Male Tourists 9537192988oolala9823
 
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝soniya singh
 
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...ur8mqw8e
 
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改atducpo
 

Recently uploaded (20)

Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
 
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdfREFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
 
办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭
 
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
(No.1)↠Young Call Girls in Sikanderpur (Gurgaon) ꧁❤ 9711911712 ❤꧂ Escorts
 
social media chat application main ppt.pptx
social media chat application main ppt.pptxsocial media chat application main ppt.pptx
social media chat application main ppt.pptx
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证
 
escort service sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
escort service  sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974escort service  sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
escort service sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
 
Powerpoint on Writing a Newspaper Report.pptx
Powerpoint on Writing a Newspaper Report.pptxPowerpoint on Writing a Newspaper Report.pptx
Powerpoint on Writing a Newspaper Report.pptx
 
E J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxE J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptx
 
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
 
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 AvilableCall Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
Call Girls In Karkardooma 83770 87607 Just-Dial Escorts Service 24X7 Avilable
 
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndCall Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
 
Cheap Rate ➥8448380779 ▻Call Girls In Mg Road Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Mg Road GurgaonCheap Rate ➥8448380779 ▻Call Girls In Mg Road Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Mg Road Gurgaon
 
Postal Ballot procedure for employees to utilise
Postal Ballot procedure for employees to utilisePostal Ballot procedure for employees to utilise
Postal Ballot procedure for employees to utilise
 
Dhule Call Girls #9907093804 Contact Number Escorts Service Dhule
Dhule Call Girls #9907093804 Contact Number Escorts Service DhuleDhule Call Girls #9907093804 Contact Number Escorts Service Dhule
Dhule Call Girls #9907093804 Contact Number Escorts Service Dhule
 
Ahmedabad Escorts Girl Services For Male Tourists 9537192988
Ahmedabad Escorts Girl Services For Male Tourists 9537192988Ahmedabad Escorts Girl Services For Male Tourists 9537192988
Ahmedabad Escorts Girl Services For Male Tourists 9537192988
 
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
 
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
 
young Call girls in Neb Sarai 🔝 9953056974 🔝 Delhi escort Service
young Call girls in Neb Sarai 🔝 9953056974 🔝 Delhi escort Serviceyoung Call girls in Neb Sarai 🔝 9953056974 🔝 Delhi escort Service
young Call girls in Neb Sarai 🔝 9953056974 🔝 Delhi escort Service
 
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
 

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 . 12/4/2020Dharma 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 12/4/2020Dharma 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. 12/4/2020Dharma 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. 12/4/2020Dharma 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}; 12/4/2020Dharma 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 12/4/2020Dharma 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]; 12/4/2020Dharma 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). 12/4/2020Dharma Kumari Kalakheti int age[5]; 10
  • 11. 12/4/2020Dharma 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(); } 12/4/2020 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. 12/4/2020 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. 12/4/2020 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. 12/4/2020 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. 12/4/2020 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. 12/4/2020 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*/ 12/4/2020 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(); } 12/4/2020 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 12/4/2020 Dharma Kumari Kalakheti 29
  • 30. 12/4/2020 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(); } 12/4/2020Dharma 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 12/4/2020Dharma Kumari Kalakheti 34
  • 35. 12/4/2020 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.