如何使用C程序打印Floyd三角形(整数)?
Floyd的三角形是一个连续数字的直角三角形,从左上角的1开始-
例如,
1 2 3 4 5 6 7 8 9 10
例子1
#include输出结果int main(){ int rows, i,j, start = 1; printf("Enter no of rows of Floyd's triangle :"); scanf("%d", &rows); for (i = 1; i <= rows; i++){ for (j = 1; j <= i; j++){ printf("%d ", start); start++; } printf("\n"); } return 0; }
Enter no of rows of Floyd's triangle :6 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
例子2
以下程序显示了如何反转弗洛伊德三角形-
#include输出结果int main() { int num, i, j; printf("输入行数: "); scanf("%d",&num); int k = num*(num+1)/2; for(i=num; i>=0; i--) { for(j=1; j<=i; j++) printf("%4d",k--); printf("\n"); } return 0; }
输入行数: 7 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短