我需要些帮助。我想要达到我的图像result上所示的结果
第一个问题...我的老师犯错了吗? 2^10 = 1024,而不是2048...?!但是nvm..
我唯一的问题是超过100.000的数字-请帮帮忙
到目前为止,我的代码如下
#include <iostream>
#include <math.h>
#include <iomanip>
#include <string>
#include <sstream>
#include <ostream>
#include <stdio.h>
#include <conio.h>
#include <fstream>
using namespace std;
int main() {
int p; // exponent
float b; // base
cout << setw(4);
for (b=1; b<11; b++) {
cout << " | " << setw(12) << b;
}
cout << endl;
for (b=1; b<=10; b++) {
cout << b;
for (p=1; p<=10; p++) {
cout << " | " << setw(12) << pow(b, p);
}
cout << endl;
}
return 0;
}它的输出是here
请帮帮忙,
诚挚的问候!
发布于 2015-12-29 07:54:32
如果问题是输出,那么最简单的做法是将pow()返回值转换为long long或编译器的64位int类型。
这将自动使用operator <<的long long重载,这将有效地删除科学记数法。
for (p=1; p<=10; p++) {
cout << " | " << static_cast<long long>(pow(b, p));Live Example
https://stackoverflow.com/questions/34502393
复制相似问题