我如何打印这个?
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/