I'm trying to figure out the avg of the sum of squares which I calculated by making a function in my program. The only problem is I dont how to count it. I think I can use the sq variable and divide it by the count, but I dont know how to count something that is calculated in a function. How would I do this? I also need to do this for the sum of cubes function. Any help is greatly appreciated thank you in advance. (function has comments)
#include <iostream>
using namespace std;
int sumsq(int); // sum of squares prototype
int sumcb(int);
int prime(int);
int main()
{
cout<<" Number SumSq SumCb PRIME "<<endl;
cout<<endl;
int numb;
int sum;
int sq;
int scb;
int count = 0;
int count1 = 0;
int count2 = 0;
for(numb=5;numb<=49;numb+=2){
count++;
sum = sum + numb;
if(prime(numb)==1){
count1++;
cout<<" "<<"*"<<endl;
}
else
cout<<endl;
cout<<" "<<numb<<" "<<sumsq(numb)<<" "<<sumcb(numb)<<endl;
sq = sumsq(numb); // sum of squares
scb = sumcb(numb);
}
cout<<endl;
cout<<"The Average of the Numbers is: "<<sum/count<<endl;
cout<<"The Average of the sum of squares is: "<<endl;
cout<<"The Average of the sum of cubes is: "<<endl;
cout<<"The Number of the prime number is: "<<count1<<endl;
system ("pause");
return 0;
}
int sumsq(int numb){ // sum of squares function
int yoyo;
int sum = 0;
for(yoyo=1;yoyo<=numb;yoyo++)
sum+= yoyo*yoyo;
return sum;
}
int sumcb(int numb){
int val;
int sum1 = 0;
for(val=1;val<=numb;val++)
sum1+= val*val*val;
return sum1;
}
int prime(int numb) {
int p;
for (p=2; p<=numb/2; p++) {
if (numb%p==0) {
return 0;
}
}
return 1;
}