C语言数组倒直角三角形

C语言数组倒直角三角形
输入 1 2 3 4 5 6 7 8 9
定义一个int[3][3]的数组
最后显示结果为
1 2 3
5 6
9
求for循环之间的代码

方法一:
#include <stdio.h>
int main()
{
int list[3][3],i;
for(i=0;i!=9;i++)
{
scanf("%d",&list[i/3][i%3]);
if(i/3<=i%3)
printf("%-2d",list[i/3][i%3]);
else
printf(" ");
if((1+i)%3==0)
printf("\n");
}
}

方法二(不用int[3][3]):
#include <stdio.h>
int main()
{
int c,i;
for(i=0;i!=9;i++)
{
scanf("%d",&c);
if(i/3<=i%3)
printf("%-2d",c);
else
printf(" ");
if((1+i)%3==0)
printf("\n");
}
}

方法三(递归):
#include <stdio.h>
void tri()
{
static int i=0,c;
if(i==9)return;
scanf("%d",&c);
i/3<=i%3?printf("%-2d",c):printf(" ");
(1+i++)%3==0?printf("\n"):0;
tri();
}
int main()
{
tri();
}
温馨提示:答案为网友推荐,仅供参考