Function pow is declared as
double pow (double base, double exponent)
that is a double.
質問
Here is a code I have written, although there is no double variable in it, g++ throws this warning: "invalid operands of types ‘double’ and ‘int’ to binary ‘operator%’ c = pow(m,e)%n; " How is that?
#include <iostream>
#include <boost/dynamic_bitset.hpp>
#include <math.h>
using namespace std;
int main()
{
boost::dynamic_bitset <> seq(5);
int key = 0;
int p = 0, q = 0;
int n = 0;
int f = 0;
int d = 0;
int e = 0;
int c = 0;
int m = 0;
int t = 0;
cout << "Enter a sequence of bits: ";
cin >> seq;
for (unsigned int i = 0; i < seq.size(); i++)
{
if ( seq[i]==1)
{
d = d + pow(2,i);
cout << d << "\n";
}
}
//cout << key << "\n";
cout << "Enter p: ";
cin >> p;
cout << "Enter q: ";
cin >> q;
cout << "Enter m: ";
cin >> m;
n = p*q;
f = (p-1)*(q-1);
for ( int k = 0; t < 1; k++)
{
if ((1+k*f)%d==0)
{
t = 2;
e = (1+k*f)/d;
}
}
cout << "E is: " << e << "\n";
c = pow(m,e)%n;
cout << "C is: " << c << "\n";
cin.get();
return 0;
}
解決
Function pow is declared as
double pow (double base, double exponent)
that is a double.