请用C++编写for,outer,inner输六行六列的*
时间: 2023-04-04 20:00:59 浏览: 55
我可以回答这个问题。以下是使用 C 语言编写的 for, outer, inner 循环,输出六行六列的 *:
```
#include <stdio.h>
int main() {
int i, j;
for (i = ; i < 6; i++) {
for (j = ; j < 6; j++) {
printf("* ");
}
printf("\n");
}
return ;
}
```
相关问题
请用c++编写
好的,以下是用 C++ 编写的代码:
```c++
#include <iostream>
using namespace std;
double fahrenheit_to_celsius(double fahrenheit) {
double celsius = (fahrenheit - 32) * 5/9;
return celsius;
}
int main() {
double fahrenheit = 75; // 假设当前华氏温度为 75 度
double celsius = fahrenheit_to_celsius(fahrenheit);
cout << fahrenheit << "华氏度等于" << celsius << "摄氏度" << endl;
return 0;
}
```
在这个示例中,我们使用 `double` 类型来存储温度值,因为它可以表示更精确的小数。我们还使用了 `iostream` 库中的 `cout` 和 `endl` 来输出结果。运行该程序将输出以下内容:
```
75华氏度等于23.8889摄氏度
```
请注意,这只是一个简单的示例,实际应用中可能需要考虑更多因素,如输入数据的有效性检查等。
用c++编写sqrt(2n*n*n+1)
可以使用cmath库中的sqrt函数来计算平方根。代码如下:
```c++
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
cout << "请输入n的值:";
cin >> n;
double result = sqrt(2 * n * n * n + 1);
cout << "结果为:" << result << endl;
return 0;
}
```
其中,输入n的值,计算出结果并输出。注意,为了避免整型相乘后溢出,需要将其中一个因数转换为double类型。