My assignment asked me to write a function that would print out a "*" when a number was prime. My output also has print out the odd numbers between 5 and 49. Anyway My function prints out only the prime number, while I want it to print out all the numbers and then just have a "*" next to a prime number. The function is at the bottom and in bold. Also if its prime it must return 1 otherwise return 0.
Thank You for any hints and help.
#include <iostream>
using namespace std;
int sumsq(int);
int sumcb(int);
int prime(int);
int main()
{
cout<<" Number SumSq SumCb PRIME "<<endl;
cout<<endl;
int numb;
int sum;
int sum1;
for(numb=5;numb<=49;numb+=2)
if(prime(numb)==1)
cout<<numb<<" "<<sumsq(numb)<<" "<<sumcb(numb)<<endl;
sum=sumsq(numb);
sum1=sumcb(numb);
system ("pause");
return 0;
}
int sumsq(int numb){
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;
}
[B]int prime(int numb) {
int p;
for (p=2; p<=numb/2; p++) {
if (numb%p==0) {
return 0;
}
}
cout << "*" << endl;
return 1;[/B]}