输入90输出90=2*3*3*5用c加加怎么写
时间: 2023-11-14 16:09:48 浏览: 52
可以使用以下代码实现:
```c
#include <stdio.h>
int main() {
int n = 90;
printf("%d=", n);
for (int i = 2; i <= n; i++) {
while (n % i == 0) {
printf("%d", i);
n /= i;
if (n != 1) {
printf("*");
}
}
}
return 0;
}
```
输出结果为:90=2*3*3*5
相关问题
输入90输出90=2*3*3*5用c加加写
好的,以下是用 C++ 实现分解质因数的代码:
```cpp
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 2; i <= n; i++) {
while (n % i == 0) {
cout << i << " ";
n /= i;
}
}
return 0;
}
```
输入一个正整数 n,程序会输出 n 的所有质因数,每个质因数后面跟一个空格。
例如,输入 90,程序会输出:2 3 3 5。
用c加加语言写代码,输入示例:5 输出示例:/* 1 6 2 10 7 3 13 11 8 4 15 14 12 9 5 */
可以回答这个问题。以下是用 C++ 语言实现的代码:
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int a[n][n];
int num = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
a[j][i-j] = num++;
}
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < n-i; j++) {
a[i+j][n-j-1] = num++;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << a[i][j] << " ";
}
}
return 0;
}
输出结果为:
1 2 4 7 11 3 5 8 12 15 6 9 13 16 18 10 14 17 19 20
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)