SlideShare a Scribd company logo
Gagan Deep
Founder & Director
Rozy Computech Services
Kurukshetra-136119, M- 9416011599
Email – rozygag@yahoo.com
Visit us at : www.rozyph.com
Arrays
 Array is a linear list of homogenous elements, stored at
successive memory locations in consecutive order.
 In C, array always starts from 0 and end with size-1 and be
written as
rollnumb[0], rollnumb[1]……….rollnumb[49]
 and be declared as
int rollnumb[50];
 means declaration syntax is
datatype arrayname [size];
 Types of array
One-Dimensional
Multi-Dimensional
One Dimensional Arrays
 Array having only one subscript variable is called one-
dimensional array and also called as single dimensional
array or linear array.
 Example of one dimensional array definition
int marks[5] = {50, 85, 60, 55, 90};
 And represented as
marks[0] =50
marks[1] = 85
marks[2] = 60
marks[3] = 55
marks[4] = 90
 A specific element in an array is accessed by an index.
Accessing One Dimensional Arrays
Program 1 : Input and output of an
Array
#include <stdio.h>
void main()
{ int marks[5],i;
printf(“Input of Array marks”);
for (i=0; i<5; i++)
scanf(“%d”, &marks[i]);
printf(“Output of Array marks”);
for (i=0; i<5; i++)
printf(“marks[%d] = %d ”, i,
marks[i]);
}
Input of Array marks
(if you entered )
50
85
60
55
90
(you will get)
Output of Array marks
marks[0] =50
marks[1] = 85
marks[2] = 60
marks[3] = 55
marks[4] = 90
Program 2 : Find the largest in an array.
#include<stdio.h>
void main() { int a[20], i, n, largest;
printf("nEnter no of elements :");
scanf("%d", &n);
for (i = 0; i < n; i++) // Input Array
scanf("%d", &a[i]);
largest = a[0]; //Consider first element as largest
for (i = 0; i < n; i++) //Process
if (a[i] > largest)
largest = a[i];
printf("nLargest Element : %d", largest); }//output largest
Program 3 : Linear Search
#include<stdio.h>
void main() { int a[20], i, n, item, loc=-1;
printf("nEnter no of elements :"); scanf("%d", &n);
for (i = 0; i < n; i++) // Input Array
scanf("%d", &a[i]);
printf("nEnter the item to be search:"); scanf("%d", &item);
for (i = 0; i < n; i++) //Process
if (a[i] == item)
{ loc= i; break; }
if (loc>=0) //output largest
printf("nItem Found: %d", loc+1);
else printf("nItem Not Found: %d" }
Program 4 : Insertion of Item in an Array
#include<stdio.h>
void main() { int a[20], i, n, j, k, item, loc;
printf("Enter the size of an array: "); scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d",&a[i]); //Input Array
printf("Enter the item to be insert: "); scanf("%d",&item);
printf(“At what location: "); scanf("%d",&loc);
j=n-1; k=loc-1;
while(j>=k){ //process
a[j+1]=a[j] ;
j=j-1; }
a[k]=item; n=n+1;
for(i=0;i<n;i++)
printf("%d",a[i]); //Output Array
Program 5 : Bubble Sort
#include<stdio.h>
void main() { int a[20], i, n, p,c;
printf("Enter the size of an array: "); scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]); //Input Array
for (p=0; p<n-1;p++) //Bubble Sort Process - Ascending
for(c=0; c< n-1-p; c++)
if a[c] > a[c+1]
{t=a[c]; a[c]=a[c+1]; a[c+1]=t;} //swapping
for(i=0;i<n;i++)
printf("%d",a[i]); //Output Array
Do Yourself
Understand Algorithms and do the programming of Following
1. Deletion from an Array
2. Merging
3. Insertion Sort
4. Selection Sort
5. Merge Sort
6. Radix Sort
7. Second Largest Element in the List
8. Delete the item from the list
9. Prime Numbers using Sieve’s Algorithm
MultiDimensional Array
 Multidimensional arrays are defined in much the same
manner as one dimensional arrays, except that a
separate square brackets required in each subscript.
 Thus, a two dimensional array will require two pairs
of square bracket,
aij -> a[i][j] -> a[rows][coulmn]
 a three dimensional array will require three pairs of
square brackets, and so on
aijk -> a[i][j][k] -> a[page][rows][coulmn]
MultiDimensional Array
 In general terms, a multidimensional array definition
can be written as
Storage –class data-type array[exp 1][exp 2]………[exp n]
 Where storage-class refers to the storage class of the
array,
 Where data-type is the data type
 array is the array name
 exp 1, exp 2 and exp n are positive valued integer
expression that indicate the number of array
elements associated with each subscripts.
2 Dimensional Array
 2 dimensional array can be expressed as
col1 col2 col3 coln
Row 1
Row 2
Row 3
Row n
X[0][0] X[0][1] X[0][n-1]
X[1][0] X[1][1] X[1][n-1]
X[n-1][0] X[n-1][1] X[n-1][n-1]
Addition of two matrices Programs 6
#include <stdio.h>
void main()
{ float a[3][3], b[3][3], c[3][3];
int i,j;
printf("Enter the elements of
1st matrixn");
for(i=0;i<3;++i)
for(j=0;j<3;++j)
scanf("%f",&a[i][j]);
printf("Enter the elements of
2nd matrixn");
for(i=0;i<3;++i)
for(j=0;j<3;++j)
scanf("%f",&b[i][j]);
for(i=0;i<3;++i)
for(j=0;j<3;++j)
c[i][j]=a[i][j]+b[i][j];
printf("nSum Of Matrix:");
for(i=0;i<3;++i)
{
for(j=0;j<3;++j)
printf("%.1ft",c[i][j]);
printf("n"); }
}
If you have any queries you can
contact me at :
rozygag@yahoo.com
Visit us at : www.rozyph.com
Ad

More Related Content

What's hot (20)

Structure in C
Structure in CStructure in C
Structure in C
Kamal Acharya
 
Strings
StringsStrings
Strings
Nilesh Dalvi
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
Shubham Sharma
 
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
imtiazalijoono
 
String functions in C
String functions in CString functions in C
String functions in C
baabtra.com - No. 1 supplier of quality freshers
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
Awais Alam
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
Priyansh Thakar
 
Strings
StringsStrings
Strings
Mitali Chugh
 
Arrays
ArraysArrays
Arrays
RaziyasultanaShaik
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
Sangani Ankur
 
Array in c++
Array in c++Array in c++
Array in c++
Mahesha Mano
 
Array in c
Array in cArray in c
Array in c
Harsh Bhanushali
 
C if else
C if elseC if else
C if else
Ritwik Das
 
Array in c
Array in cArray in c
Array in c
Ravi Gelani
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
Rabin BK
 
String in c programming
String in c programmingString in c programming
String in c programming
Devan Thakur
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
tanmaymodi4
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
Smit Parikh
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Harendra Singh
 

Viewers also liked (7)

Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
EngineerBabu
 
Dbs3024 biz trx week 2 double entry system
Dbs3024 biz trx week 2 double entry systemDbs3024 biz trx week 2 double entry system
Dbs3024 biz trx week 2 double entry system
Stephen Ong
 
Double entry system
Double entry systemDouble entry system
Double entry system
RaJesh Thakur
 
Double entry systme
Double entry systmeDouble entry systme
Double entry systme
Asian Institute of Virtual Learning
 
Double Entry
Double EntryDouble Entry
Double Entry
creativemedia
 
Array in C
Array in CArray in C
Array in C
Kamal Acharya
 
Arrays
ArraysArrays
Arrays
archikabhatia
 
Ad

Similar to C Programming : Arrays (20)

02 arrays
02 arrays02 arrays
02 arrays
Rajan Gautam
 
CP Handout#7
CP Handout#7CP Handout#7
CP Handout#7
trupti1976
 
presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.ppt
NamakkalPasanga
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
nmahi96
 
Module 5 PPS.pptnwnekdnndkdkdnnsksosmsna
Module 5 PPS.pptnwnekdnndkdkdnnsksosmsnaModule 5 PPS.pptnwnekdnndkdkdnnsksosmsna
Module 5 PPS.pptnwnekdnndkdkdnnsksosmsna
mitivete
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
HimanshuKansal22
 
Arrays
ArraysArrays
Arrays
Steven Wallach
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
Ashim Lamichhane
 
Arrays
ArraysArrays
Arrays
VenkataRangaRaoKommi1
 
SPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in CSPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in C
Mohammad Imam Hossain
 
Arrays
ArraysArrays
Arrays
Aman Agarwal
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
ajajkhan16
 
Module_3_Arrays - Updated.pptx............
Module_3_Arrays - Updated.pptx............Module_3_Arrays - Updated.pptx............
Module_3_Arrays - Updated.pptx............
ChiragKankani
 
Unit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTUREUnit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTURE
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Array
ArrayArray
Array
PralhadKhanal1
 
1D Array
1D Array1D Array
1D Array
A. S. M. Shafi
 
Arrays In C
Arrays In CArrays In C
Arrays In C
yndaravind
 
Array
ArrayArray
Array
hjasjhd
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
Thesis Scientist Private Limited
 
Array assignment
Array assignmentArray assignment
Array assignment
Ahmad Kamal
 
Ad

More from Gagan Deep (20)

Number system
Number systemNumber system
Number system
Gagan Deep
 
Fundamentals of Neural Networks
Fundamentals of Neural NetworksFundamentals of Neural Networks
Fundamentals of Neural Networks
Gagan Deep
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
Gagan Deep
 
Software Project Planning V
Software Project Planning VSoftware Project Planning V
Software Project Planning V
Gagan Deep
 
Software Project Planning IV
Software Project Planning IVSoftware Project Planning IV
Software Project Planning IV
Gagan Deep
 
Software Project Planning III
Software Project Planning IIISoftware Project Planning III
Software Project Planning III
Gagan Deep
 
Software Project Planning II
Software Project Planning IISoftware Project Planning II
Software Project Planning II
Gagan Deep
 
Software Project Planning 1
Software Project Planning 1Software Project Planning 1
Software Project Planning 1
Gagan Deep
 
Software Engineering
Software Engineering Software Engineering
Software Engineering
Gagan Deep
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
Gagan Deep
 
C – A Programming Language- I
C – A Programming Language- IC – A Programming Language- I
C – A Programming Language- I
Gagan Deep
 
System Analysis & Design - 2
System Analysis & Design - 2System Analysis & Design - 2
System Analysis & Design - 2
Gagan Deep
 
System Analysis & Design - I
System Analysis & Design - ISystem Analysis & Design - I
System Analysis & Design - I
Gagan Deep
 
Information System and MIS
Information System and MISInformation System and MIS
Information System and MIS
Gagan Deep
 
SQL – A Tutorial I
SQL – A Tutorial  ISQL – A Tutorial  I
SQL – A Tutorial I
Gagan Deep
 
Boolean algebra
Boolean algebraBoolean algebra
Boolean algebra
Gagan Deep
 
Normalization 1
Normalization 1Normalization 1
Normalization 1
Gagan Deep
 
Normalization i i
Normalization   i iNormalization   i i
Normalization i i
Gagan Deep
 
Plsql overview
Plsql overviewPlsql overview
Plsql overview
Gagan Deep
 
Fundamentals of Neural Networks
Fundamentals of Neural NetworksFundamentals of Neural Networks
Fundamentals of Neural Networks
Gagan Deep
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
Gagan Deep
 
Software Project Planning V
Software Project Planning VSoftware Project Planning V
Software Project Planning V
Gagan Deep
 
Software Project Planning IV
Software Project Planning IVSoftware Project Planning IV
Software Project Planning IV
Gagan Deep
 
Software Project Planning III
Software Project Planning IIISoftware Project Planning III
Software Project Planning III
Gagan Deep
 
Software Project Planning II
Software Project Planning IISoftware Project Planning II
Software Project Planning II
Gagan Deep
 
Software Project Planning 1
Software Project Planning 1Software Project Planning 1
Software Project Planning 1
Gagan Deep
 
Software Engineering
Software Engineering Software Engineering
Software Engineering
Gagan Deep
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
Gagan Deep
 
C – A Programming Language- I
C – A Programming Language- IC – A Programming Language- I
C – A Programming Language- I
Gagan Deep
 
System Analysis & Design - 2
System Analysis & Design - 2System Analysis & Design - 2
System Analysis & Design - 2
Gagan Deep
 
System Analysis & Design - I
System Analysis & Design - ISystem Analysis & Design - I
System Analysis & Design - I
Gagan Deep
 
Information System and MIS
Information System and MISInformation System and MIS
Information System and MIS
Gagan Deep
 
SQL – A Tutorial I
SQL – A Tutorial  ISQL – A Tutorial  I
SQL – A Tutorial I
Gagan Deep
 
Boolean algebra
Boolean algebraBoolean algebra
Boolean algebra
Gagan Deep
 
Normalization 1
Normalization 1Normalization 1
Normalization 1
Gagan Deep
 
Normalization i i
Normalization   i iNormalization   i i
Normalization i i
Gagan Deep
 
Plsql overview
Plsql overviewPlsql overview
Plsql overview
Gagan Deep
 

Recently uploaded (20)

Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 

C Programming : Arrays

  • 1. Gagan Deep Founder & Director Rozy Computech Services Kurukshetra-136119, M- 9416011599 Email – [email protected] Visit us at : www.rozyph.com
  • 2. Arrays  Array is a linear list of homogenous elements, stored at successive memory locations in consecutive order.  In C, array always starts from 0 and end with size-1 and be written as rollnumb[0], rollnumb[1]……….rollnumb[49]  and be declared as int rollnumb[50];  means declaration syntax is datatype arrayname [size];  Types of array One-Dimensional Multi-Dimensional
  • 3. One Dimensional Arrays  Array having only one subscript variable is called one- dimensional array and also called as single dimensional array or linear array.  Example of one dimensional array definition int marks[5] = {50, 85, 60, 55, 90};  And represented as marks[0] =50 marks[1] = 85 marks[2] = 60 marks[3] = 55 marks[4] = 90  A specific element in an array is accessed by an index.
  • 4. Accessing One Dimensional Arrays Program 1 : Input and output of an Array #include <stdio.h> void main() { int marks[5],i; printf(“Input of Array marks”); for (i=0; i<5; i++) scanf(“%d”, &marks[i]); printf(“Output of Array marks”); for (i=0; i<5; i++) printf(“marks[%d] = %d ”, i, marks[i]); } Input of Array marks (if you entered ) 50 85 60 55 90 (you will get) Output of Array marks marks[0] =50 marks[1] = 85 marks[2] = 60 marks[3] = 55 marks[4] = 90
  • 5. Program 2 : Find the largest in an array. #include<stdio.h> void main() { int a[20], i, n, largest; printf("nEnter no of elements :"); scanf("%d", &n); for (i = 0; i < n; i++) // Input Array scanf("%d", &a[i]); largest = a[0]; //Consider first element as largest for (i = 0; i < n; i++) //Process if (a[i] > largest) largest = a[i]; printf("nLargest Element : %d", largest); }//output largest
  • 6. Program 3 : Linear Search #include<stdio.h> void main() { int a[20], i, n, item, loc=-1; printf("nEnter no of elements :"); scanf("%d", &n); for (i = 0; i < n; i++) // Input Array scanf("%d", &a[i]); printf("nEnter the item to be search:"); scanf("%d", &item); for (i = 0; i < n; i++) //Process if (a[i] == item) { loc= i; break; } if (loc>=0) //output largest printf("nItem Found: %d", loc+1); else printf("nItem Not Found: %d" }
  • 7. Program 4 : Insertion of Item in an Array #include<stdio.h> void main() { int a[20], i, n, j, k, item, loc; printf("Enter the size of an array: "); scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); //Input Array printf("Enter the item to be insert: "); scanf("%d",&item); printf(“At what location: "); scanf("%d",&loc); j=n-1; k=loc-1; while(j>=k){ //process a[j+1]=a[j] ; j=j-1; } a[k]=item; n=n+1; for(i=0;i<n;i++) printf("%d",a[i]); //Output Array
  • 8. Program 5 : Bubble Sort #include<stdio.h> void main() { int a[20], i, n, p,c; printf("Enter the size of an array: "); scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); //Input Array for (p=0; p<n-1;p++) //Bubble Sort Process - Ascending for(c=0; c< n-1-p; c++) if a[c] > a[c+1] {t=a[c]; a[c]=a[c+1]; a[c+1]=t;} //swapping for(i=0;i<n;i++) printf("%d",a[i]); //Output Array
  • 9. Do Yourself Understand Algorithms and do the programming of Following 1. Deletion from an Array 2. Merging 3. Insertion Sort 4. Selection Sort 5. Merge Sort 6. Radix Sort 7. Second Largest Element in the List 8. Delete the item from the list 9. Prime Numbers using Sieve’s Algorithm
  • 10. MultiDimensional Array  Multidimensional arrays are defined in much the same manner as one dimensional arrays, except that a separate square brackets required in each subscript.  Thus, a two dimensional array will require two pairs of square bracket, aij -> a[i][j] -> a[rows][coulmn]  a three dimensional array will require three pairs of square brackets, and so on aijk -> a[i][j][k] -> a[page][rows][coulmn]
  • 11. MultiDimensional Array  In general terms, a multidimensional array definition can be written as Storage –class data-type array[exp 1][exp 2]………[exp n]  Where storage-class refers to the storage class of the array,  Where data-type is the data type  array is the array name  exp 1, exp 2 and exp n are positive valued integer expression that indicate the number of array elements associated with each subscripts.
  • 12. 2 Dimensional Array  2 dimensional array can be expressed as col1 col2 col3 coln Row 1 Row 2 Row 3 Row n X[0][0] X[0][1] X[0][n-1] X[1][0] X[1][1] X[1][n-1] X[n-1][0] X[n-1][1] X[n-1][n-1]
  • 13. Addition of two matrices Programs 6 #include <stdio.h> void main() { float a[3][3], b[3][3], c[3][3]; int i,j; printf("Enter the elements of 1st matrixn"); for(i=0;i<3;++i) for(j=0;j<3;++j) scanf("%f",&a[i][j]); printf("Enter the elements of 2nd matrixn"); for(i=0;i<3;++i) for(j=0;j<3;++j) scanf("%f",&b[i][j]); for(i=0;i<3;++i) for(j=0;j<3;++j) c[i][j]=a[i][j]+b[i][j]; printf("nSum Of Matrix:"); for(i=0;i<3;++i) { for(j=0;j<3;++j) printf("%.1ft",c[i][j]); printf("n"); } }
  • 14. If you have any queries you can contact me at : [email protected] Visit us at : www.rozyph.com