Professional Documents
Culture Documents
L AB E XE RC I SE :
Program 1:
Write a function to print Sum and average of all the elements of an array. The parameters to function are
array and size of the array. Use the function in your program for array of 10 elements.
#include<iostream>
using namespace std;
int largest(int a[], int size)
{
int large=0;
for(int i=0; i<size;i++)
{
if(a[i]>large)
{
large=a[i];
}
}
return large;
}
int main()
{
int a[10];
cout<<"Enter 10 Numbers :"<<endl;
for(int i=0; i<10; i++)
{
cin>>a[i];
}
cout<<"Largest Number = "<<largest(a,10)<<endl;
system("PAUSE");
return 0;
}
Sample Output: Program 1
Program 2:
Write a function to return the largest element of an array. The parameters to function are array and size of
array. Use the function in your program for array of 10 elements.
#include<iostream>
using namespace std;
int main()
{
int a[10];
sumAverage(a,10);
system("PAUSE");
return 0;
}
int main()
{
int a[5];
reverse(a,10);
cout<<endl<<endl;
system("PAUSE");
return 0;
}
Sample Output: Program 3