[ create a new paste ] login | about

Link: http://codepad.org/Gjlb6Uno    [ raw code | output | fork ]

C++, pasted on May 11:
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;

int highest(int [], int);
int lowest(int[], int);
double average(int[],int);

int main()
{
const int SIZE=20;
int grades[SIZE];
for (int x=0; x<20; x++)
{
grades[x]=x*x;
}

cout<<"The highest grade is: "<<highest(grades, SIZE)<<endl;
cout<<"The lowest grade is: "<<lowest(grades, SIZE)<<endl;
cout<<"The average grade is: "<<average(grades, SIZE)<<endl;
return 0;

}

int lowest(int grades[],int SIZE)
{
int lowest=grades[0];
for(int count=1; count<SIZE; count++)
{
if(grades[count]<lowest)
lowest=grades[count];
}
return lowest;
}

int highest(int grades[],int SIZE)
{
int highest=grades[0];
for(int count=1; count<SIZE; count++)
{
if(grades[count]>highest)
highest=grades[count];
}

return highest;
}

double average(int grades[],int SIZE)
{
double average=0.0;
int total(0);
for(int count=0;count<SIZE; count++)
{
total+=grades[count];
}
average=total/20;
return average;
}


Output:
1
2
3
The highest grade is: 361
The lowest grade is: 0
The average grade is: 123


Create a new paste based on this one


Comments: