用dev c++写一个代码,一个数列的前三个数是0,0,1,以后的每个数都是前三个数的和。输入一个大于5小于100的正整数n,输出该数列的前n项,按每项占6列,每行4项的形式输出
时间: 2024-05-04 08:16:42 浏览: 11
好的,我明白了你的要求。以下是你想要的 Dev C++ 代码:
```c++
#include<stdio.h>
int main()
{
int nums[100];
int n, i;
printf("请输入一个大于5小于100的正整数n:");
scanf("%d", &n);
nums[0] = 0;
nums[1] = 0;
nums[2] = 1;
for(i = 3; i < n; i++)
{
nums[i] = nums[i-1] + nums[i-2] + nums[i-3];
}
printf("数列的前%d项为:\n", n);
for(i = 0; i < n; i++)
{
printf("%-6d", nums[i]);
if((i+1) % 4 == 0)
{
printf("\n");
}
}
return 0;
}
```
希望对你有帮助!如果你还有其他问题可以继续问我。
相关问题
用devc++写一个烟花代码
以下是使用Dev-C++编写的烟花代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define WIDTH 80
#define HEIGHT 24
int main(void) {
int x, y, i;
char screen[HEIGHT][WIDTH];
srand(time(NULL)); // 用当前时间初始化随机数生成器
// 初始化屏幕
for (y = 0; y < HEIGHT; y++)
for (x = 0; x < WIDTH; x++)
screen[y][x] = ' ';
// 随机生成烟花的花瓣
for (i = 0; i < 50; i++) {
x = rand() % WIDTH; // 随机生成横坐标
y = rand() % HEIGHT; // 随机生成纵坐标
screen[y][x] = '*'; // 在屏幕上绘制烟花花瓣
}
// 输出屏幕
for (y = 0; y < HEIGHT; y++) {
for (x = 0; x < WIDTH; x++)
putchar(screen[y][x]);
putchar('\n');
}
return 0;
}
```
用devc++写一个玫瑰代码
以下是使用Dev-C++编写玫瑰代码的示例:
```c
#include <stdio.h>
#include <math.h>
int main()
{
int r, x, y, size;
double d;
printf("请输入玫瑰的大小(建议在10-100之间):");
scanf("%d", &size);
for (y = -size / 2; y < size / 2; y++)
{
for (x = -size / 2; x < size / 2; x++)
{
d = sqrt(x * x + y * y);
r = (int)(sin(d / size * 4 * M_PI) * size / 2);
if (r == 0)
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
return 0;
}
```
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![h](https://img-home.csdnimg.cn/images/20210720083646.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)