任意の数nmの積を求めるプログラムを作っているのですが、10^9までの積など、大きい数を扱うためにはどうしたらいいでしょう?(1~10など小さい数ならできます)
1
このコードに改良を加えるとしたらどこでしょう?
#include <iostream>
#include <string>
using namespace std;
int main()
{
long a,b,c=1;
cin >> a >> b;
while (a <= b){
c = c * a;
a = a+1;
}
if (0<c){
cout <<"Positive"<<endl;
}
else if (0>c){
cout <<"Negative"<<endl;
}
else cout <<"Zero"<<endl;
}
回答2件
あなたの回答
tips
プレビュー