c - 需要一些提示或帮助得出算法来打印以下内容

标签 c

我如何打印这个?

1 3 6 10 15
2 5 9 14
4 8 13
7 12
11

我能够得出以下代码,但我不确定如何组合以下代码来产生我想要的结果。

#include <stdio.h>
int main()
{
    int n = 5;
    int start = a;
    int i;
    int j;
    for (j = 1; j <= n; j++) /* This for loop produce 1 3 6 10 15 */
    {
        start = start + j;
        printf("%d ", start);
    }

    printf("\n");
    start = 1;
    for (i = 0; i < 5; i++) /* This for loop produce 1 2 4 7 11 */
    {
        start = start + i;
        printf("%d ", start);

    }
    return 0;
}

请指导我,因为我真的不擅长编程。

最佳答案

如果您只想打印上述图案,最快的方法是:

#include <stdio.h>

int main(){
    puts("1 3 6 10 15");
    puts("2 5 9 14");
    puts("4 8 13");
    puts("7 12");
    puts("11");
    return 0;
}

P.S:您没有接受用户的任何输入。

关于c - 需要一些提示或帮助得出算法来打印以下内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26581068/

相关文章:

c++ - C/C++ 库的想法

c++ - 从 engOpen(..) 启动 matlab,被通知引擎被关闭

c - 有什么办法可以避免静态内存区域溢出吗?

c - 在 C 中使用 YACC 对 LISP 子集进行操作

c - void 名称(类型名称1,类型名称2,类型名称3[名称1][名称2]);

c - 出队功能不起作用

c - PAM 模块错误(传递 ‘snprintf’ 的参数 1 会丢弃 ‘const’ )

C编程排序函数错误

无法在 SQLITE、C API 中准备 INSERT 语句

java - 为什么 GetLastError() 会阻止我的方法?