你好!
对于1--91构成的“弗洛伊德三角形”
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
.......
79 .............. 91
可以通过以下C程序实现:
程序一:
#include
#define N 10
int main()
{
int i,j,l;
for(i=1,j=1;i<=N;i++)
{
for(l=1;l printf("%5d",j);
printf("\n");
}
return 0;
}
程序二:
#include "stdafx.h"
int main (void)
{
int col,temp=1,n;
for(col=1;temp<91;col++)
{
for(n=1;n<=col;n++,temp++)
{if(temp<10)
printf("%d ",temp);
else
printf("%d ",temp);}
printf("\n");
}
getchar();
}
程序三:
#include"stdio.h"
int main()
{
int i ,j=1 ,k=1;
for (i=1;i<92;i++)
{
printf ("%d ",i);
if (j==k)
{
printf ("\n");
k++;
j=0;
}
j++;
}
getchar();
return 0;
}
程序四:
main()
{
int a,b,c;
b=0;c=1;
for(a=1;a<=91;a++)
{
printf("%4d",a);
if(c==a-b)
{
printf("\n");
b=a;
c=c+1;
}
}
}
程序五:
main()
{
int a,n,l;
a=0;n=1;l=0;
for( ;a<=12;a++)
{
l=a+n;
for( ;n<=l;n++)
printf("%3d",n);
printf("\n");
}
}