SlideShare una empresa de Scribd logo
1 de 15
Array is a collection of identical data objects which are stored
in consecutive memory locations under a common heading or a
variable name.
Array Declaration
storage_class data_type array_name[expression];
static char page[8];
where storage_class refers to the scope of the array variable
such as external, static, automatic.
09/04/131 VIT - SCSE
Array
Array Initialization
storage_class data_type array_name[expression] = {element 1,
element 2,……,element n};
Types of Array
1. Single Dimensional Array
2. Two Dimensional Array
3. Multi Dimensional Array
09/04/132 VIT - SCSE
Single Dimensional
#include<iostream.h>
void main()
{
int a[7]={11,12,13,14,15,16,17};
int i;
cout<<”Contents of the array n”;
for(i=0;i<6;i++)
{
cout<<a[i]<<’t’;
}}
09/04/133 VIT - SCSE
A program to read a set of numbers
from the keyboard and to find out the
largest number in the given array.
#include<iostream.h>
void main()
{ int a[100];
int i,n,larg;
cout<<”How many numbers are in
the array?”<<endl;
cin>>n;
cout<<”Enter the
elements”<<endl;
for(i=0;i<=n-1;i++)
{ cin>>a[i];
}
09/04/134 VIT - SCSE
cout<<”Contents of the
array”<<endl;
for(i=0;i<=n-1;i++)
{
cout<<a[i]<<’t’;
}
cout<<endl;
larg=a[0];
for(i=0;i<=n-1;i++)
{
if(larg<a[i])
larg=a[i];
}
cout<<”Largest value in
the array=”<<larg;
}
A program to read a set of numbers from the standard input device
and to sort them in ascending order.
09/04/135 VIT - SCSE
cout<<endl;
for(i=0;i<=n-1;i++)
{ for(j=0;j<=n-1;j++)
if(a[i]<a[j])
{ temp=a[i];
a[i]=a[j];
a[j]=temp;
} }
cout<<”Contents(sorted
form)”<<endl;
for(i=0;i<=n-1;i++)
{ cout<<a[i]<<’t’;
}
cout<<endl;
}
#include<iostream.h>
void main()
{ int a[100];
int i,j,n,temp;
cout<<”How many numbers are
in the array?”<<endl;
cin>>n;
cout<<”Enter the
elements”<<endl;
for(i=0;i<=n-1;i++)
{ cin>>a[i];
}cout<<”Contents”<<endl;
for(i=0;i<=n-1;i++)
{cout<<a[i]<<’t’;
}
A program to read a set of numbers from the keyboard and to find out the
sum of all elements of the given array using function
09/04/136 VIT - SCSE
Arrays and Functions
for(i=0;i<=n-1;i++)
{
cin>>a[i];
}
cout<<”Output from the
array”<<endl;
output(a,n);
sum=sumarray(a,n);
cout<<endl;
cout<<”Sum of the
values of the
array=”<<sum;
}
#include<iostream.h>
#define MAX 100
void main()
{
void output(int a[],int n);
int sumarray(int a[],int n);
int a[MAX];
int I,n,sum;
cout<<”How many numbers are in
the array?”<<endl;
cin>>n;
cout<<”Enter the elements”<<endl;
09/04/137 VIT - SCSE
void output(int a[],int n)
{ cout<<endl;
for(i=0;i<=n-1;i++)
{
cout<<a[i]<<’t’;
} }
int sumarray(int x[],int max)
{
int value=0;
for(int i=0;i<=max-1;i++)
{
value=value+x[i];
}
return(value);
}
09/04/138 VIT - SCSE
Multidimensional Array
Syntax:
storage_class data_type arrayname[expr1][expr2]….[exprn];
float value[10][10];
int line[20][10][5];
A program to initialize a set of numbers in a two dimensional array and to
display the content of the array on the screen
09/04/139 VIT - SCSE
cout<<”Contents of the
array”<<endl;
for(i=0;i<=N-1;i++)
{
for(j=0;j<=M-1;j++)
cout<<a[i][j]<<’t’;
cout<<endl;
}
}
#include<iostream.h>
#define N 3
#define M 4
void main()
{
int i,j;
float a[N][M] = { {1,2,3,4},
{5,6,7,8},
{9,10,11,12}
};
Character Array
char page[40];
09/04/1310 VIT - SCSE
#include<iostream.h>
void main()
{
int i;
char name[5]={‘r’,’a’,’v’,’i’};
cout<<”Contents of the array”<<endl;
for(i=0;i<=4;i++)
{
cout<<”name[“<<i<<”]=”<<name[i]<<endl;
}
}
Pointer
09/04/1311 VIT - SCSE
Pointer Declaration
Pointer Operator (*)
Address Operator (&)
#include<iostream.h>
void main()
{
char x,y;
char *p;
x=’c’;
p=&x;
y=*p;
cout<<”Value of x=”<<x<<endl;
cout<<”pointer value=”<<y<<endl;
}
Pointer Arithmetic
+, -, ++, --
09/04/1312 VIT - SCSE
#include<iostream.h>
void main()
{
int x,y;
int *p;
x=10;
p=&x;
cout<<”value of x=”<<x<<”and pointer=”;
cout<<*p<<endl;
y=*p+1;
cout<<”Value of y=”<<y<<”and pointer=”;
cout<<*p<<endl;
}
Pointers and Functions
09/04/1313 VIT - SCSE
Use of the pointers in a function definition may be
classified in to two groups.
1.call by value
2.call by reference
call by value
//A program to exchange the contents of two variables using a call by value
09/04/1314 VIT - SCSE
#include<iostream.h>
void main()
{
int x,y;
void swap(int,int);
x=100;
y=200;
cout<<”values before swap”<<endl;
cout<<”x=”<<x<<”y=”<<y<<endl;
swap(x,y);
cout<<”values after swap”<<endl;
cout<<”x=”<<x<<”y=”<<y<<endl;
}
void swap(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
}
call by reference
Address of the actual arguments are copied onto the formal arguments
09/04/1315 VIT - SCSE
#include<iostream.h>
void main()
{
int x,y;
void swap(int *x,int *y);
x=100;
y=200;
cout<<”values before swap”<<endl;
cout<<”x=”<<x<<”y=”<<y<<endl;
swap(&x,&y);
cout<<”values after swap”<<endl;
cout<<”x=”<<x<<”y=”<<y<<endl;
}
void swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}

Más contenido relacionado

La actualidad más candente

Array in c programming
Array in c programmingArray in c programming
Array in c programmingMazharul Islam
 
Dynamics allocation
Dynamics allocationDynamics allocation
Dynamics allocationKumar
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : ArraysGagan Deep
 
Object Oriented Programming - 5.1. Array
Object Oriented Programming - 5.1. ArrayObject Oriented Programming - 5.1. Array
Object Oriented Programming - 5.1. ArrayAndiNurkholis1
 
Array in c language
Array in c languageArray in c language
Array in c languageumesh patil
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationRabin BK
 
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 in c language
Array in c language Array in c language
Array in c language umesh patil
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c languagetanmaymodi4
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array pptsandhya yadav
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional arrayRajendran
 

La actualidad más candente (19)

Arrays
ArraysArrays
Arrays
 
Array C programming
Array C programmingArray C programming
Array C programming
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
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
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
Dynamics allocation
Dynamics allocationDynamics allocation
Dynamics allocation
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
Object Oriented Programming - 5.1. Array
Object Oriented Programming - 5.1. ArrayObject Oriented Programming - 5.1. Array
Object Oriented Programming - 5.1. Array
 
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
 
Structures
StructuresStructures
Structures
 
intorduction to Arrays in java
intorduction to Arrays in javaintorduction to Arrays in java
intorduction to Arrays in java
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
 
Array lecture
Array lectureArray lecture
Array lecture
 
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 in c language
Array in c language Array in c language
Array in c language
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 

Similar a 5 array

array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdfHEMAHEMS5
 
Arrays_in_c++.pptx
Arrays_in_c++.pptxArrays_in_c++.pptx
Arrays_in_c++.pptxMrMaster11
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functionsSwarup Boro
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2YOGESH SINGH
 
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
 
Write an application that stores 12 integers in an array. Display the.docx
 Write an application that stores 12 integers in an array. Display the.docx Write an application that stores 12 integers in an array. Display the.docx
Write an application that stores 12 integers in an array. Display the.docxajoy21
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programmingnmahi96
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.pptFareedIhsas
 

Similar a 5 array (20)

ARRAYSCPP.pptx
ARRAYSCPP.pptxARRAYSCPP.pptx
ARRAYSCPP.pptx
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
Arrays_in_c++.pptx
Arrays_in_c++.pptxArrays_in_c++.pptx
Arrays_in_c++.pptx
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
02 arrays
02 arrays02 arrays
02 arrays
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
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
 
Arrays
ArraysArrays
Arrays
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Write an application that stores 12 integers in an array. Display the.docx
 Write an application that stores 12 integers in an array. Display the.docx Write an application that stores 12 integers in an array. Display the.docx
Write an application that stores 12 integers in an array. Display the.docx
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
Array.ppt
Array.pptArray.ppt
Array.ppt
 
Array.ppt
Array.pptArray.ppt
Array.ppt
 
Arrays
ArraysArrays
Arrays
 
Array
ArrayArray
Array
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
 

Más de Docent Education

12 constructors invocation and data members initialization
12 constructors invocation and data members initialization12 constructors invocation and data members initialization
12 constructors invocation and data members initializationDocent Education
 
12 constructors invocation and data members initialization
12 constructors invocation and data members initialization12 constructors invocation and data members initialization
12 constructors invocation and data members initializationDocent Education
 
11 constructors in derived classes
11 constructors in derived classes11 constructors in derived classes
11 constructors in derived classesDocent Education
 
4 Type conversion functions
4 Type conversion functions4 Type conversion functions
4 Type conversion functionsDocent Education
 
1 Intro Object Oriented Programming
1  Intro Object Oriented Programming1  Intro Object Oriented Programming
1 Intro Object Oriented ProgrammingDocent Education
 

Más de Docent Education (15)

17 files and streams
17 files and streams17 files and streams
17 files and streams
 
16 virtual function
16 virtual function16 virtual function
16 virtual function
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
 
13 exception handling
13 exception handling13 exception handling
13 exception handling
 
12 constructors invocation and data members initialization
12 constructors invocation and data members initialization12 constructors invocation and data members initialization
12 constructors invocation and data members initialization
 
12 constructors invocation and data members initialization
12 constructors invocation and data members initialization12 constructors invocation and data members initialization
12 constructors invocation and data members initialization
 
11 constructors in derived classes
11 constructors in derived classes11 constructors in derived classes
11 constructors in derived classes
 
10 inheritance
10 inheritance10 inheritance
10 inheritance
 
7 class objects
7 class objects7 class objects
7 class objects
 
6 pointers functions
6 pointers functions6 pointers functions
6 pointers functions
 
4 Type conversion functions
4 Type conversion functions4 Type conversion functions
4 Type conversion functions
 
1 Intro Object Oriented Programming
1  Intro Object Oriented Programming1  Intro Object Oriented Programming
1 Intro Object Oriented Programming
 
3 intro basic_elements
3 intro basic_elements3 intro basic_elements
3 intro basic_elements
 
2 Intro c++
2 Intro c++2 Intro c++
2 Intro c++
 
unit-1-intro
 unit-1-intro unit-1-intro
unit-1-intro
 

Último

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 

Último (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

5 array

  • 1. Array is a collection of identical data objects which are stored in consecutive memory locations under a common heading or a variable name. Array Declaration storage_class data_type array_name[expression]; static char page[8]; where storage_class refers to the scope of the array variable such as external, static, automatic. 09/04/131 VIT - SCSE Array
  • 2. Array Initialization storage_class data_type array_name[expression] = {element 1, element 2,……,element n}; Types of Array 1. Single Dimensional Array 2. Two Dimensional Array 3. Multi Dimensional Array 09/04/132 VIT - SCSE
  • 3. Single Dimensional #include<iostream.h> void main() { int a[7]={11,12,13,14,15,16,17}; int i; cout<<”Contents of the array n”; for(i=0;i<6;i++) { cout<<a[i]<<’t’; }} 09/04/133 VIT - SCSE
  • 4. A program to read a set of numbers from the keyboard and to find out the largest number in the given array. #include<iostream.h> void main() { int a[100]; int i,n,larg; cout<<”How many numbers are in the array?”<<endl; cin>>n; cout<<”Enter the elements”<<endl; for(i=0;i<=n-1;i++) { cin>>a[i]; } 09/04/134 VIT - SCSE cout<<”Contents of the array”<<endl; for(i=0;i<=n-1;i++) { cout<<a[i]<<’t’; } cout<<endl; larg=a[0]; for(i=0;i<=n-1;i++) { if(larg<a[i]) larg=a[i]; } cout<<”Largest value in the array=”<<larg; }
  • 5. A program to read a set of numbers from the standard input device and to sort them in ascending order. 09/04/135 VIT - SCSE cout<<endl; for(i=0;i<=n-1;i++) { for(j=0;j<=n-1;j++) if(a[i]<a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } cout<<”Contents(sorted form)”<<endl; for(i=0;i<=n-1;i++) { cout<<a[i]<<’t’; } cout<<endl; } #include<iostream.h> void main() { int a[100]; int i,j,n,temp; cout<<”How many numbers are in the array?”<<endl; cin>>n; cout<<”Enter the elements”<<endl; for(i=0;i<=n-1;i++) { cin>>a[i]; }cout<<”Contents”<<endl; for(i=0;i<=n-1;i++) {cout<<a[i]<<’t’; }
  • 6. A program to read a set of numbers from the keyboard and to find out the sum of all elements of the given array using function 09/04/136 VIT - SCSE Arrays and Functions for(i=0;i<=n-1;i++) { cin>>a[i]; } cout<<”Output from the array”<<endl; output(a,n); sum=sumarray(a,n); cout<<endl; cout<<”Sum of the values of the array=”<<sum; } #include<iostream.h> #define MAX 100 void main() { void output(int a[],int n); int sumarray(int a[],int n); int a[MAX]; int I,n,sum; cout<<”How many numbers are in the array?”<<endl; cin>>n; cout<<”Enter the elements”<<endl;
  • 7. 09/04/137 VIT - SCSE void output(int a[],int n) { cout<<endl; for(i=0;i<=n-1;i++) { cout<<a[i]<<’t’; } } int sumarray(int x[],int max) { int value=0; for(int i=0;i<=max-1;i++) { value=value+x[i]; } return(value); }
  • 8. 09/04/138 VIT - SCSE Multidimensional Array Syntax: storage_class data_type arrayname[expr1][expr2]….[exprn]; float value[10][10]; int line[20][10][5];
  • 9. A program to initialize a set of numbers in a two dimensional array and to display the content of the array on the screen 09/04/139 VIT - SCSE cout<<”Contents of the array”<<endl; for(i=0;i<=N-1;i++) { for(j=0;j<=M-1;j++) cout<<a[i][j]<<’t’; cout<<endl; } } #include<iostream.h> #define N 3 #define M 4 void main() { int i,j; float a[N][M] = { {1,2,3,4}, {5,6,7,8}, {9,10,11,12} };
  • 10. Character Array char page[40]; 09/04/1310 VIT - SCSE #include<iostream.h> void main() { int i; char name[5]={‘r’,’a’,’v’,’i’}; cout<<”Contents of the array”<<endl; for(i=0;i<=4;i++) { cout<<”name[“<<i<<”]=”<<name[i]<<endl; } }
  • 11. Pointer 09/04/1311 VIT - SCSE Pointer Declaration Pointer Operator (*) Address Operator (&) #include<iostream.h> void main() { char x,y; char *p; x=’c’; p=&x; y=*p; cout<<”Value of x=”<<x<<endl; cout<<”pointer value=”<<y<<endl; }
  • 12. Pointer Arithmetic +, -, ++, -- 09/04/1312 VIT - SCSE #include<iostream.h> void main() { int x,y; int *p; x=10; p=&x; cout<<”value of x=”<<x<<”and pointer=”; cout<<*p<<endl; y=*p+1; cout<<”Value of y=”<<y<<”and pointer=”; cout<<*p<<endl; }
  • 13. Pointers and Functions 09/04/1313 VIT - SCSE Use of the pointers in a function definition may be classified in to two groups. 1.call by value 2.call by reference
  • 14. call by value //A program to exchange the contents of two variables using a call by value 09/04/1314 VIT - SCSE #include<iostream.h> void main() { int x,y; void swap(int,int); x=100; y=200; cout<<”values before swap”<<endl; cout<<”x=”<<x<<”y=”<<y<<endl; swap(x,y); cout<<”values after swap”<<endl; cout<<”x=”<<x<<”y=”<<y<<endl; } void swap(int x,int y) { int temp; temp=x; x=y; y=temp; }
  • 15. call by reference Address of the actual arguments are copied onto the formal arguments 09/04/1315 VIT - SCSE #include<iostream.h> void main() { int x,y; void swap(int *x,int *y); x=100; y=200; cout<<”values before swap”<<endl; cout<<”x=”<<x<<”y=”<<y<<endl; swap(&x,&y); cout<<”values after swap”<<endl; cout<<”x=”<<x<<”y=”<<y<<endl; } void swap(int *x,int *y) { int temp; temp=*x; *x=*y; *y=temp; }