c语言循环
用循环来弄的 int i=0,j=0,n=0;scanf("%d",&n);
while(i<n)
{
j=0;
while(j<i+1)
{
printf("%3d ",(1+i)*i/2+j+1);
j++;
}
printf("\n");
i++;
} int i=0,j=0,n=0;
scanf("%d",&n);
n=(1+n)*n/2;
i=1,j=1;
while(i<=n)
{
printf("%3d ",i);
if (i==(1+j)*j/2)
{
j++;
printf("\n");
}
i++;
}
return 0; 本帖最后由 傻眼貓咪 于 2021-12-31 21:22 编辑
#include <stdio.h>
int main(){
int n, a = 0, b;
scanf("%d", &n);
while(++a != n+1){
b = (((a-1)*a) >> 1) + 1;
while(b < (((a*(a+1)) >> 1) + 1)) printf("%3d ", b++);
printf("\n");
}
return 0;
}
页:
[1]