Date: 02/04/2025
1. C++ Program to display elements in an array:
#include<iostream>
using namespace std;
int main(){
int a[20],n,i;
cout<<"Enter the size of array:\n";
cin>>n;
cout<<"Enter the elements:\n";
for(i=0;i<n;i++){
cin>>a[i];
}
cout<<"The elements are:\n";
for(i=0;i<n;i++){
cout<<a[i]<<"\t";
}
return 0;
}
Date: 02/04/2025
2. C++ Program to calculate the sum of elements in the array and display it:
#include<iostream>
using namespace std;
int main(){
int a[20],n,i, sum=0;
cout<<"Enter the size of array:\n";
cin>>n;
cout<<"Enter the elements:\n";
for(i=0;i<n;i++){
cin>>a[i];
}
cout<<"The elements are:\n";
for(i=0;i<n;i++){
cout<<a[i]<<"\t";
}
for(i=0;i<n;i++){
sum=sum+a[i];
}
cout<<"\nThe sum of the elements is \n"<<sum;
return 0;
}
Date: 02/04/2025
3. C++ Program to display the elements and its respective address in the array:
#include<iostream>
using namespace std;
int main(){
int a[20],n,i;
cout<<"Enter the size of array:\n";
cin>>n;
cout<<"Enter the elements:\n";
for(i=0;i<n;i++){
cin>>a[i];
}
cout<<"The elements are:\n";
for(i=0;i<n;i++){
cout<<a[i]<<"\t";
}
cout<<"\nThe address of the elements is \n";
for(i=0;i<n;i++){
cout<<&a[i]<<", ";
}
return 0;
}
Date: 02/04/2025
4. C++ Program to read n number of array elements and display them in reverse order:
#include<iostream>
using namespace std;
int main(){
int a[20],n,i;
cout<<"Enter the size of array:\n";
cin>>n;
cout<<"Enter the elements:\n";
for(i=0;i<n;i++){
cin>>a[i];
}
cout<<"The elements are:\n";
for(i=0;i<n;i++){
cout<<a[i]<<"\t";
}
cout<<"\nThe elements in reverse order are:\n";
for(i=n-1;i>=0;i--){
cout<<a[i]<<"\t";
}
return 0;
}
Date: 02/04/2025
5. C++ Program to copy elements of an array to another array:
#include<iostream>
using namespace std;
int main(){
int a[20],b[20],n,i;
cout<<"Enter the size of array:\n";
cin>>n;
cout<<"Enter the elements:\n";
for(i=0;i<n;i++){
cin>>a[i];
}
cout<<"The elements are:\n";
for(i=0;i<n;i++){
cout<<a[i]<<"\t";
}
for(i=0;i<n;i++){
b[i]=a[i];
}
cout<<"\nThe elements of second array are:\n";
for(i=0;i<n;i++){
cout<<b[i]<<"\t";
}
return 0;
}
Date: 02/04/2025
6. C++ Program to find maximum and minimum element in an array:
#include<iostream>
using namespace std;
int main(){
int a[20],n,i,max,min;
cout<<"Enter the size of array:\n";
cin>>n;
cout<<"Enter the elements:\n";
for(i=0;i<n;i++){
cin>>a[i];
}
cout<<"The elements are:\n";
for(i=0;i<n;i++){
cout<<a[i]<<"\t";
}
max=a[0];
for(i=0;i<n;i++){
if(a[i]>max){
max=a[i];
}
}
cout<<"\nMaximum element is:\n"<<max;
min=a[0];
for(i=0;i<n;i++){
if(a[i]<min){
min=a[i];
}
}
cout<<"\nMinimum element is:\n"<<min;
return 0;
}
Date: 02/04/2025
7. C++ Program to display odd and even numbers from the array list.
#include<iostream>
using namespace std;
int main(){
int a[20],n,i,max,min;
cout<<"Enter the size of array:\n";
cin>>n;
cout<<"Enter the elements:\n";
for(i=0;i<n;i++){
cin>>a[i];
}
cout<<"The elements are:\n";
for(i=0;i<n;i++){
cout<<a[i]<<"\t";
}
cout<<"\nThe even elements are:\n";
for(i=0;i<n;i++){
if(a[i]%2==0){
cout<<a[i]<<"\t";
}
}
cout<<"\nThe odd elements are:\n";
for(i=0;i<n;i++){
if(a[i]%2!=0){
cout<<a[i]<<"\t";
}
}
return 0;
}