【发布时间】:2018-09-21 19:25:27
【问题描述】:
我无法让这段代码按我想要的方式工作。任务是编写一个程序,打印输入的数字 n (1
#include <iostream>
using namespace std;
int main(){
int n;
int j;
int r=0;
int t=1;
double f=1;
cin>>n;
for(int p=1;p<=n-1;p++){
t=t*10;
}
int u=t;
//calculates the factorial of n
for(int o=1;o<=n;o++){
f=f*o;
}
//writes numbers from 1 to n into an integer
for(int d=1;d<=n;d++){
j=d*u;
r=r+j;
u=u/10;
}
}
【问题讨论】:
-
在这里使用一致的缩进会有很大帮助,否则你会迷失在复杂性中。
-
我有点难以理解您的预期输出,如果我为 n 输入 8,我希望输出是什么?
-
预期输出将是 40320 的排列数,然后是从 1 到 8 的所有数字排列(12345678,13245678...)。
-
std::next_permutation 不需要数组吗?
标签: c++ permutation