do-while循环计算1*1+2*3+3*5+…+n*(2*n-1)的前50项结果。
时间: 2023-10-26 11:06:20 浏览: 68
```
#include <stdio.h>
int main() {
int n = 1;
int i = 1;
do {
printf("%d * %d = %d\n", n, 2*n-1, n*(2*n-1));
n++;
i++;
} while (i <= 50);
return 0;
}
```
相关问题
用while和do-while循环计算1*1+2*3+3*5+…+n*(2*n-1)的前50项结果。
使用while循环:
```
int n = 1;
int count = 0;
while(count < 50) {
System.out.println(n * (2 * n - 1));
n++;
count++;
}
```
使用do-while循环:
```
int n = 1;
int count = 0;
do {
System.out.println(n * (2 * n - 1));
n++;
count++;
} while(count < 50);
```
两种循环的效果是一样的,都能计算出1*1 2*3 3*5 … n*(2*n-1)的前50项结果。
用while和do-while循环计算1*c语言:1+2*3+3*5+…+n*(2*n-1)的前50项结果。
使用while循环:
```c
#include <stdio.h>
int main() {
int n = 1;
int count = 0;
while(count < 50) {
printf("%d ", n * (2 * n - 1));
n++;
count++;
}
return 0;
}
```
使用do-while循环:
```c
#include <stdio.h>
int main() {
int n = 1;
int count = 0;
do {
printf("%d ", n * (2 * n - 1));
n++;
count++;
} while(count < 50);
return 0;
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)