#include<iostream>
using namespace std;
class array{
int array[100],n,small,large;
int sum = 0;
public:
void input();
void average();
void largest();
};
void array::input()
{
cout<<"Enter the no of elements you want to enter:";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Enter element "<<i+1<<":";
cin>>array[i];
}
}
void array::average()
{
for(int counter = 0; counter<n;counter++)
{
sum+=array[counter];
}
int average = sum /n;
cout<<"Average of the elements of the array:"<<average;
}
void array::largest()
{
small=array[0];
large=array[0];
for(int j=1;j<n;j++)
{
if(array[j]<small)
small=array[j];
if(array[j]>large)
large=array[j];
}
cout<<"\nLargest element is :"<<large;
}
int main()
{
array k;
k.input();
k.average();
k.largest();
return 0;
}
OUTPUT:
using namespace std;
class array{
int array[100],n,small,large;
int sum = 0;
public:
void input();
void average();
void largest();
};
void array::input()
{
cout<<"Enter the no of elements you want to enter:";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Enter element "<<i+1<<":";
cin>>array[i];
}
}
void array::average()
{
for(int counter = 0; counter<n;counter++)
{
sum+=array[counter];
}
int average = sum /n;
cout<<"Average of the elements of the array:"<<average;
}
void array::largest()
{
small=array[0];
large=array[0];
for(int j=1;j<n;j++)
{
if(array[j]<small)
small=array[j];
if(array[j]>large)
large=array[j];
}
cout<<"\nLargest element is :"<<large;
}
int main()
{
array k;
k.input();
k.average();
k.largest();
return 0;
}
OUTPUT:
No comments:
Post a Comment