#include <iostream>
using namespace std;
int num, prime, a, x, y, times;
int exponentiation(num, prime){
times = 0;
while (a % prime == 0){
times += prime;
a = a / prime;
}
if(times > 0){
cout << prime << "^" << times;
}
}
int main()
{
cin >> a;
exponentiation(a, 2);
for(x = 3; x <= 10000; x++){
for(y = 3; y <= x; y++){
if(x % y == 0)
break;
else if (x == y + 1)
exponentiation(a, x);
}
}
return 0;
}
I was trying to factorize numbers with cpp and came up with the idea of declaring a function to figure out how many times a prime number can divide my number so that I'll just have to put all the prime numbers in to get results like 2(prime numers)^3(returned by the function)
However the compiler said that my function cannot be used as a function for some reason. Can someone tell me what's the problem? Is it the function or the main part where things went wrong?
int exponentiation(num, prime){
->int exponentiation(int num,int prime){
. Voting to close as typo. Also the function either needs return typevoid
or return somethingint exponentiation(num, prime) int num; int prime; { /*...*/ }
. But C++ is not C, and it's been several decades since that style was supplanted in C byint exponentiation(int num, int prime) { /*...*/ }
.