cs201 assignemnt no. 2 solution

No Comments
#include<iostream.h>
#include<conio.h>
float avg(int [],int);
float low(int [],int);
float high(int [],int);

int main()
{
int n;
cout<<"Enter the number of consecutive days to read their temperature";
cin>>n;
cout<<endl;

int arr[10];
float l,h,a;
for(int i=0;i<n;i++)
{
cout<<"Enter the temperature for day "<<i+1<<" : ";
cin>>arr[i];
cout<<endl;
}
cout<<endl;
a=avg(arr,n);
cout<<"The Average Temperature is "<<a<<endl;
h=high(arr,n);
cout<<"The Highest temperature is "<<h<<endl;
l=low(arr,n);
cout<<"The Lowest temperature is "<<l;


getch();
}

float avg(int arr[],int n)
{
float sum=0.0,a;
for(int i=0;i<n;i++)
{
sum=sum+arr[i];

}
a=sum/5.0;
return (a);
}

float low(int arr[],int n)
{
float l=100.0;
for(int i=0;i<n;i++)
{
if(arr[i]<l)
l=arr[i];
}

return (l);
}
float high(int arr[],int n)
{
float h=0.0;
for(int i=0;i<n;i++)
{
if(arr[i]>h)
h=arr[i];


}

return (h);
}
Next PostNewer Post Previous PostOlder Post Home

0 comments

Post a Comment