Arrays Lab Tasks Complete
Arrays Lab Tasks Complete
Roll.no:22sw076
Arrays-Lab-Tasks
Task # 1: Write a C++ program that creates and initializes an array of type integer as :int
array[]={5,10,15,20,25}; and computes the SUM of the elements in an array
#include<iostream>
int main()
int a[]={5,10,15,20,25};
int sum=0;
for(int i=0;i<5;i++){
cout <<”a[“<<i<<”]=”<<a[i]<<endl;
sum+=a[i];
cout <<”sum=”<<sum;
return 0;
Task #2 Consider the array in Taskno.2 . Write a C++ program that print the all elements of the
array in reverse order, As 25,20, …5.
#include<iostream>
using namespace std;
int main()
{
int a[]={5,10,15,20,25};
for(int i=4;i>=0;i--){
cout <<a[i]<<”,”;
}
return 0;
}
Task#3 Consider the following interger array of size 10.
int array[10]={1,2,3,5,8,10,12,23,28,15};
Write a c++ program that takes an integer value from the user at runtime and finds that value in
the given array . If the value is found display Message “Number is Found “ else display
Message “Number does not Found “.
#include<iostream>
int main()
int a[10]={1,2,3,5,8,10,12,23,28,15};
int a,x;
cin>>a;
for(int i=0;i<10;i++){
if(a==a[i]){
x=a;
if(x==a){
cout<<”number is found”;
}
else
return 0;
Task #4 Consider the array in Taskno.3 . Write a C++ program that finds and prints all odd
numbers in the given array.
#include<iostream>
int main()
int a[10]={1,2,3,5,8,10,12,23,28,15};
for(int i=0;i<10;i++){
if(a[i]%2!=0){
cout<<a[i]<<” “;
return 0;
Task #5 : Write a C++ program that prints the second last element in the array created in
Taskno. 2. And also displays the sum and product of last two elements of the array.
#include<iostream>
Using namespace std;
int main()
{
int a[]={5,10,15,20,25};
int main()
{
int a[]={5,8,75,0,9},m,i,n;
for ( i=1;i<5;i++){
if(a[0]>a[i]){
m=a[i];
n=i;}
}
cout <<”smallest element :”<<m;
cout <<endl<<”index: “<<n;
return 0;
}
Task #8 : Write a C++ program that passes an array (of your choice) as an argument to a
function.
#include <iostream>
using namespace std;
void fun(int arry[5])
{