SlideShare a Scribd company logo
Array
An array is a finite set of same type of data items. In other word it is a collection of homogeneous
data items.
The elements of an array are stored in successive memory locations. An element of an array is
referred by array name and index number (subscript).
Types of array
1. One dimensional (1-D) or linear array
2. Two dimensional (2-D) array
1-D Array
An array that can be represented by only one dimension such as row or column and that holds
finite number of same type of data items is called one dimensional array.
Array B
1 2 3 4 5 6 7 8 9
0 10 12 13 19 20 23 18 29
Fig: Graphical representation of 1-D array
1, 2, …………., 9 index number
0, 10, …….., 29 data items or elements of the array
B the array name
Symbolically the element of the array is expressed as Bi or B[i], which denotes ith
element of the
array.
Store/retrieve an element into/from an array
int a[10], i, n;
scanf(“%d”, &n);
for(i=1;i<=n;i++)
{
scanf(“%d”, &a[i]);
}
for(i=1;i<=n;i++)
{
printf(“%d”, a[i]);
}
C Program to Store/retrieve an element into/from an array
#include <stdio.h>
int main()
{
int a[100], i, n;
printf("Enter number of elements in arrayn");
scanf("%d", &n);
printf("Enter %d elementsn", n);
for (i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
}
printf("Array elementsn");
for (i = 1; i <= n; i++)
{
printf("%dt", a[i]);
}
return 0;
}
Sample Output
Enter number of elements in array
5
Enter 5 elements
1
2
3
4
5
Array elements
1 2 3 4 5
Algorithm to search the largest element of a list
1. Input x[1….n]
2. for(i=1;i<=n;i++)
Store data to x[i];
3. large=x[1];
4. for(i=2;i<=n;i++)
if(large<x[i])
large=x[i];
5. Output: The largest number (print the value of large)
C program to search the largest element of a list
#include<stdio.h>
#include<conio.h>
int main()
{
int x[100],i,n,large;
printf("Enter the number of elements: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&x[i]);
}
large=x[1];
for(i=2;i<=n;i++)
{
if(large<x[i])
{
large=x[i];
}
}
printf("The largest among the %d elements is %d",n,large);
return 0;
}
Sample Output
Enter the number of elements: 5
12
6
7
9
0
The largest among the 5 elements is 12
Algorithm to search a particular element from a list
1. Input: A set of data in array a, and variable x. i.e., the target element
a[1….n], x;
2. found=0
3. for (i=1; i<=n; i++)
{
if (a[i]==x)
location=i;
found= 1;
break;
}
4. Output: if (found==1)
print”FOUND” message and location.
else print ”NOT FOUND” message
C program to search a particular element from a list
#include <stdio.h>
int main()
{
int array[100], search, c, n;
printf("Enter the number of elements in arrayn");
scanf("%d",&n);
printf("Enter %d integer(s)n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
printf("Enter the number to searchn");
scanf("%d", &search);
for (c = 0; c < n; c++)
{
if (array[c] == search)
{
printf("%d is present at location %d.n", search, c+1);
break;
}
}
if (c == n)
printf("%d is not present in array.n", search);
return 0;
}
Sample Output
Enter the number of elements in array
6
Enter 6 integer(s)
3
4
0
2
9
7
Enter the number to search
0
0 is present at location 3.
Algorithm to find out the summations of even and odd numbers
1. Input: An array and variable (to store the results of summations)
A[1….n], sum_odd=0, sum_even=0;
2. for (i=1; i<=n; i++)
{
if(A[i]%2==0), sum_even=sum_even+A[i];
else sum_odd=sum_odd+A[i];
}
3. Output: Summationof odd numbers (print sum_odd) and
Summation of even numbers (print sum_even)
C program to find out the summations of even and odd numbers
#include <stdio.h>
int main()
{
int array[100], i, num, sum_of_odd = 0, sum_of_even = 0;
printf("Enter the number of elementsn");
scanf("%d", &num);
printf("Enter the elements n");
for(i=1;i<=num;i++)
{
scanf("%d",&array[i]);
}
for (i = 1; i <= num; i++)
{
if (array[i] % 2 == 0)
sum_of_even = sum_of_even + array[i];
else
sum_of_odd = sum_of_odd + array[i];
}
printf("Sum of all odd numbers = %dn", sum_of_odd);
printf("Sum of all even numbers = %dn", sum_of_even);
return 0;
}
Sample Output
Enter the number of elements
5
Enter the elements
1
2
5
3
9
Sum of all odd numbers = 18
Sum of all even numbers = 2
Algorithm to find out the summations of even and odd indexed numbers
1. Input: An array and variable (to store the results of summations)
A[1….n], sum_odd=0, sum_even=0;
2. for (i=1; i<=n; i++)
{
if(i%2==0), sum_even=sum_even+A[i];
else sum_odd=sum_odd+A[i];
}
3. Output: Summation of numbers in odd indices (print sum_odd) and
Summation of numbers in even indices (print sum_even)
C program to find out the summations of even and odd indexed numbers
#include <stdio.h>
int main()
{
int array[100], i, num, sum_of_odd = 0, sum_of_even = 0;
printf("Enter the number of elementsn");
scanf("%d", &num);
printf("Enter the elements n");
for(i=1;i<=num;i++)
{
scanf("%d",&array[i]);
}
for (i = 1; i <= num; i++)
{
if (i % 2 == 0)
sum_of_even = sum_of_even + array[i];
else
sum_of_odd = sum_of_odd + array[i];
}
printf("Sum of all odd number indices = %dn", sum_of_odd);
printf("Sum of all even number indices = %dn", sum_of_even);
return 0;
}
Sample Output
Enter the number of elements
5
Enter the elements
1
2
5
8
7
Sum of all odd number indices = 13
Sum of all even number indices = 10
Algorithm to insert an element into an array
1. Input: An array A[1….n], the position of insertion m and the data x.
2. Increase the size of the array, A[1….n+1]
3. for (i=n; i>=m; i--)
A[i+1]=A[i];
4. A[m]=x;
5. Output: The array, A with size n+1
C program to insert an element into an array
#include <stdio.h>
int main()
{
int array[100], position, c, n, value;
printf("Enter number of elements in arrayn");
scanf("%d", &n);
printf("Enter %d elementsn", n);
for (c = 1; c <= n; c++)
{
scanf("%d", &array[c]);
}
printf("Enter the location where you wish to insert an
elementn");
scanf("%d", &position);
printf("Enter the value to insertn");
scanf("%d", &value);
for (c = n; c >= position; c--)
{
array[c+1] = array[c];
}
array[position] = value;
printf("Resultant array isn");
for (c = 1; c <= n+1; c++)
{
printf("%dn", array[c]);
}
return 0;
}
Sample Output
Enter number of elements in array
5
Enter 5 elements
1
2
3
7
5
Enter the location where you wish to insert an element
4
Enter the value to insert
0
Resultant array is
1
2
3
0
7
5
Algorithm to delete an element from an array
1. Input: An array A[1….n], the position of deletion m.
2. for (i=m; i<n; i++)
A[i]=A[i+1];
3. Output: The updated array, A
C program to delete an element from an array
#include <stdio.h>
int main()
{
int array[100], position, c, n;
printf("Enter number of elements in arrayn");
scanf("%d", &n);
printf("Enter %d elementsn", n);
for ( c = 1 ; c <= n ; c++ )
{
scanf("%d", &array[c]);
}
printf("Enter the location where you wish to delete
elementn");
scanf("%d", &position);
if ( position >= n+1 )
printf("Deletion not possible.n");
else
{
for ( c = position ; c < n ; c++ )
{
array[c] = array[c+1];
}
printf("Resultant array isn");
for( c = 1 ; c < n ; c++ )
printf("%dn", array[c]);
}
return 0;
}
Sample Output
Enter number of elements in array
4
Enter 4 elements
8
9
0
3
Enter the location where you wish to delete element
2
Resultant array is
8
0
3

More Related Content

What's hot

design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
Nitesh Dubey
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
ArghodeepPaul
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
PRATHAMESH DESHPANDE
 
Python lab manual all the experiments are available
Python lab manual all the experiments are availablePython lab manual all the experiments are available
Python lab manual all the experiments are available
Nitesh Dubey
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
Arkadeep Dey
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
University of Potsdam
 
LAB PROGRAMS SARASWATHI RAMALINGAM
LAB PROGRAMS SARASWATHI RAMALINGAMLAB PROGRAMS SARASWATHI RAMALINGAM
LAB PROGRAMS SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysisVishal Singh
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointers
Sushil Mishra
 
SPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested LoopSPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested Loop
Mohammad Imam Hossain
 
4. chapter iii
4. chapter iii4. chapter iii
4. chapter iii
Chhom Karath
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
sandeep kumbhkar
 

What's hot (19)

Ds
DsDs
Ds
 
Vcs17
Vcs17Vcs17
Vcs17
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Python lab manual all the experiments are available
Python lab manual all the experiments are availablePython lab manual all the experiments are available
Python lab manual all the experiments are available
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
 
LAB PROGRAMS SARASWATHI RAMALINGAM
LAB PROGRAMS SARASWATHI RAMALINGAMLAB PROGRAMS SARASWATHI RAMALINGAM
LAB PROGRAMS SARASWATHI RAMALINGAM
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointers
 
SPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested LoopSPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested Loop
 
Thesis PPT
Thesis PPTThesis PPT
Thesis PPT
 
4. chapter iii
4. chapter iii4. chapter iii
4. chapter iii
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 

Similar to 1D Array

programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdf
sowmya koneru
 
presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.ppt
NamakkalPasanga
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
HimanshuKansal22
 
02 arrays
02 arrays02 arrays
02 arrays
Rajan Gautam
 
Ada file
Ada fileAda file
Ada file
Kumar Gaurav
 
Examples sandhiya class'
Examples sandhiya class'Examples sandhiya class'
Examples sandhiya class'
Dr.Sandhiya Ravi
 
Array Programs.pdf
Array Programs.pdfArray Programs.pdf
Array Programs.pdf
RajKamal557276
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
Gagan Deep
 
ADA FILE
ADA FILEADA FILE
ADA FILE
Gaurav Singh
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
rushabhshah600
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
Kandarp Tiwari
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
Rumman Ansari
 
Unit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTUREUnit 2 dsa LINEAR DATA STRUCTURE
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
YOGESH SINGH
 
unit-2-dsa.pptx
unit-2-dsa.pptxunit-2-dsa.pptx
unit-2-dsa.pptx
sayalishivarkar1
 
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
 
2D array
2D array2D array
2D array
A. S. M. Shafi
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
Nooryaseen9
 

Similar to 1D Array (20)

programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdf
 
presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.ppt
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
array.ppt
array.pptarray.ppt
array.ppt
 
02 arrays
02 arrays02 arrays
02 arrays
 
Ada file
Ada fileAda file
Ada file
 
Examples sandhiya class'
Examples sandhiya class'Examples sandhiya class'
Examples sandhiya class'
 
Array Programs.pdf
Array Programs.pdfArray Programs.pdf
Array Programs.pdf
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
Arrays
ArraysArrays
Arrays
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
Unit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTUREUnit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTURE
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
unit-2-dsa.pptx
unit-2-dsa.pptxunit-2-dsa.pptx
unit-2-dsa.pptx
 
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
 
2D array
2D array2D array
2D array
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
 

More from A. S. M. Shafi

2D Transformation in Computer Graphics
2D Transformation in Computer Graphics2D Transformation in Computer Graphics
2D Transformation in Computer Graphics
A. S. M. Shafi
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphics
A. S. M. Shafi
 
Projection
ProjectionProjection
Projection
A. S. M. Shafi
 
2D Transformation
2D Transformation2D Transformation
2D Transformation
A. S. M. Shafi
 
Line drawing algorithm
Line drawing algorithmLine drawing algorithm
Line drawing algorithm
A. S. M. Shafi
 
Fragmentation
FragmentationFragmentation
Fragmentation
A. S. M. Shafi
 
File organization
File organizationFile organization
File organization
A. S. M. Shafi
 
Bankers algorithm
Bankers algorithmBankers algorithm
Bankers algorithm
A. S. M. Shafi
 
RR and priority scheduling
RR and priority schedulingRR and priority scheduling
RR and priority scheduling
A. S. M. Shafi
 
Fcfs and sjf
Fcfs and sjfFcfs and sjf
Fcfs and sjf
A. S. M. Shafi
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
A. S. M. Shafi
 
Stack push pop
Stack push popStack push pop
Stack push pop
A. S. M. Shafi
 
Queue
QueueQueue
Searching
SearchingSearching
Searching
A. S. M. Shafi
 
Sorting
SortingSorting
Linked list
Linked listLinked list
Linked list
A. S. M. Shafi
 
Sum of subset problem
Sum of subset problemSum of subset problem
Sum of subset problem
A. S. M. Shafi
 
Quick sort
Quick sortQuick sort
Quick sort
A. S. M. Shafi
 
N queens problem
N queens problemN queens problem
N queens problem
A. S. M. Shafi
 
MST
MSTMST

More from A. S. M. Shafi (20)

2D Transformation in Computer Graphics
2D Transformation in Computer Graphics2D Transformation in Computer Graphics
2D Transformation in Computer Graphics
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphics
 
Projection
ProjectionProjection
Projection
 
2D Transformation
2D Transformation2D Transformation
2D Transformation
 
Line drawing algorithm
Line drawing algorithmLine drawing algorithm
Line drawing algorithm
 
Fragmentation
FragmentationFragmentation
Fragmentation
 
File organization
File organizationFile organization
File organization
 
Bankers algorithm
Bankers algorithmBankers algorithm
Bankers algorithm
 
RR and priority scheduling
RR and priority schedulingRR and priority scheduling
RR and priority scheduling
 
Fcfs and sjf
Fcfs and sjfFcfs and sjf
Fcfs and sjf
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Stack push pop
Stack push popStack push pop
Stack push pop
 
Queue
QueueQueue
Queue
 
Searching
SearchingSearching
Searching
 
Sorting
SortingSorting
Sorting
 
Linked list
Linked listLinked list
Linked list
 
Sum of subset problem
Sum of subset problemSum of subset problem
Sum of subset problem
 
Quick sort
Quick sortQuick sort
Quick sort
 
N queens problem
N queens problemN queens problem
N queens problem
 
MST
MSTMST
MST
 

Recently uploaded

Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 

Recently uploaded (20)

Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 

1D Array

  • 1. Array An array is a finite set of same type of data items. In other word it is a collection of homogeneous data items. The elements of an array are stored in successive memory locations. An element of an array is referred by array name and index number (subscript). Types of array 1. One dimensional (1-D) or linear array 2. Two dimensional (2-D) array 1-D Array An array that can be represented by only one dimension such as row or column and that holds finite number of same type of data items is called one dimensional array. Array B 1 2 3 4 5 6 7 8 9 0 10 12 13 19 20 23 18 29 Fig: Graphical representation of 1-D array 1, 2, …………., 9 index number 0, 10, …….., 29 data items or elements of the array B the array name Symbolically the element of the array is expressed as Bi or B[i], which denotes ith element of the array. Store/retrieve an element into/from an array int a[10], i, n; scanf(“%d”, &n); for(i=1;i<=n;i++) { scanf(“%d”, &a[i]); } for(i=1;i<=n;i++) { printf(“%d”, a[i]);
  • 2. } C Program to Store/retrieve an element into/from an array #include <stdio.h> int main() { int a[100], i, n; printf("Enter number of elements in arrayn"); scanf("%d", &n); printf("Enter %d elementsn", n); for (i = 1; i <= n; i++) { scanf("%d", &a[i]); } printf("Array elementsn"); for (i = 1; i <= n; i++) { printf("%dt", a[i]); } return 0; } Sample Output Enter number of elements in array 5 Enter 5 elements 1 2 3 4
  • 3. 5 Array elements 1 2 3 4 5 Algorithm to search the largest element of a list 1. Input x[1….n] 2. for(i=1;i<=n;i++) Store data to x[i]; 3. large=x[1]; 4. for(i=2;i<=n;i++) if(large<x[i]) large=x[i]; 5. Output: The largest number (print the value of large) C program to search the largest element of a list #include<stdio.h> #include<conio.h> int main() { int x[100],i,n,large; printf("Enter the number of elements: "); scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&x[i]); } large=x[1]; for(i=2;i<=n;i++) { if(large<x[i])
  • 4. { large=x[i]; } } printf("The largest among the %d elements is %d",n,large); return 0; } Sample Output Enter the number of elements: 5 12 6 7 9 0 The largest among the 5 elements is 12 Algorithm to search a particular element from a list 1. Input: A set of data in array a, and variable x. i.e., the target element a[1….n], x; 2. found=0 3. for (i=1; i<=n; i++) { if (a[i]==x) location=i; found= 1; break; } 4. Output: if (found==1) print”FOUND” message and location.
  • 5. else print ”NOT FOUND” message C program to search a particular element from a list #include <stdio.h> int main() { int array[100], search, c, n; printf("Enter the number of elements in arrayn"); scanf("%d",&n); printf("Enter %d integer(s)n", n); for (c = 0; c < n; c++) scanf("%d", &array[c]); printf("Enter the number to searchn"); scanf("%d", &search); for (c = 0; c < n; c++) { if (array[c] == search) { printf("%d is present at location %d.n", search, c+1); break; } } if (c == n) printf("%d is not present in array.n", search); return 0; } Sample Output Enter the number of elements in array
  • 6. 6 Enter 6 integer(s) 3 4 0 2 9 7 Enter the number to search 0 0 is present at location 3. Algorithm to find out the summations of even and odd numbers 1. Input: An array and variable (to store the results of summations) A[1….n], sum_odd=0, sum_even=0; 2. for (i=1; i<=n; i++) { if(A[i]%2==0), sum_even=sum_even+A[i]; else sum_odd=sum_odd+A[i]; } 3. Output: Summationof odd numbers (print sum_odd) and Summation of even numbers (print sum_even) C program to find out the summations of even and odd numbers #include <stdio.h> int main() { int array[100], i, num, sum_of_odd = 0, sum_of_even = 0; printf("Enter the number of elementsn");
  • 7. scanf("%d", &num); printf("Enter the elements n"); for(i=1;i<=num;i++) { scanf("%d",&array[i]); } for (i = 1; i <= num; i++) { if (array[i] % 2 == 0) sum_of_even = sum_of_even + array[i]; else sum_of_odd = sum_of_odd + array[i]; } printf("Sum of all odd numbers = %dn", sum_of_odd); printf("Sum of all even numbers = %dn", sum_of_even); return 0; } Sample Output Enter the number of elements 5 Enter the elements 1 2 5 3 9 Sum of all odd numbers = 18 Sum of all even numbers = 2
  • 8. Algorithm to find out the summations of even and odd indexed numbers 1. Input: An array and variable (to store the results of summations) A[1….n], sum_odd=0, sum_even=0; 2. for (i=1; i<=n; i++) { if(i%2==0), sum_even=sum_even+A[i]; else sum_odd=sum_odd+A[i]; } 3. Output: Summation of numbers in odd indices (print sum_odd) and Summation of numbers in even indices (print sum_even) C program to find out the summations of even and odd indexed numbers #include <stdio.h> int main() { int array[100], i, num, sum_of_odd = 0, sum_of_even = 0; printf("Enter the number of elementsn"); scanf("%d", &num); printf("Enter the elements n"); for(i=1;i<=num;i++) { scanf("%d",&array[i]); } for (i = 1; i <= num; i++) { if (i % 2 == 0) sum_of_even = sum_of_even + array[i]; else sum_of_odd = sum_of_odd + array[i];
  • 9. } printf("Sum of all odd number indices = %dn", sum_of_odd); printf("Sum of all even number indices = %dn", sum_of_even); return 0; } Sample Output Enter the number of elements 5 Enter the elements 1 2 5 8 7 Sum of all odd number indices = 13 Sum of all even number indices = 10 Algorithm to insert an element into an array 1. Input: An array A[1….n], the position of insertion m and the data x. 2. Increase the size of the array, A[1….n+1] 3. for (i=n; i>=m; i--) A[i+1]=A[i]; 4. A[m]=x; 5. Output: The array, A with size n+1 C program to insert an element into an array #include <stdio.h> int main() { int array[100], position, c, n, value;
  • 10. printf("Enter number of elements in arrayn"); scanf("%d", &n); printf("Enter %d elementsn", n); for (c = 1; c <= n; c++) { scanf("%d", &array[c]); } printf("Enter the location where you wish to insert an elementn"); scanf("%d", &position); printf("Enter the value to insertn"); scanf("%d", &value); for (c = n; c >= position; c--) { array[c+1] = array[c]; } array[position] = value; printf("Resultant array isn"); for (c = 1; c <= n+1; c++) { printf("%dn", array[c]); } return 0; } Sample Output Enter number of elements in array 5 Enter 5 elements
  • 11. 1 2 3 7 5 Enter the location where you wish to insert an element 4 Enter the value to insert 0 Resultant array is 1 2 3 0 7 5 Algorithm to delete an element from an array 1. Input: An array A[1….n], the position of deletion m. 2. for (i=m; i<n; i++) A[i]=A[i+1]; 3. Output: The updated array, A C program to delete an element from an array #include <stdio.h> int main() { int array[100], position, c, n; printf("Enter number of elements in arrayn"); scanf("%d", &n);
  • 12. printf("Enter %d elementsn", n); for ( c = 1 ; c <= n ; c++ ) { scanf("%d", &array[c]); } printf("Enter the location where you wish to delete elementn"); scanf("%d", &position); if ( position >= n+1 ) printf("Deletion not possible.n"); else { for ( c = position ; c < n ; c++ ) { array[c] = array[c+1]; } printf("Resultant array isn"); for( c = 1 ; c < n ; c++ ) printf("%dn", array[c]); } return 0; } Sample Output Enter number of elements in array 4 Enter 4 elements 8 9
  • 13. 0 3 Enter the location where you wish to delete element 2 Resultant array is 8 0 3