您好,欢迎访问一九零五行业门户网

编写一个在C语言中打印数字模式的程序

程序说明数字模式是根据称为模式规则的规则创建的数字序列。模式规则可以使用一个或多个数学运算来描述序列中连续数字之间的关系。
模式示例
模式 1
12 63 7 104 8 11 135 9 12 14 15
模式 2
1 1 2 3 1 2 3 4 5 1 2 3 4 5 6 71 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 1 2 3 4 5 1 2 3 1
算法pattern 1:i stands for rows and j stands for columns.5 stands for making pattern for 5 rows and columnsloop for each row (i)k is initialized to iloop for each column (j)do the pattern for the current column (j)display the value of kreinitialize the value of k = k + 5 - jpattern 2:first row: display 1second row: display 1,2,3third row: display 1,2,3,4,5fourth row: display 1,2,3,4,5,6,7fifth row: display 1,2,3,4,5,6,7,8,9display the same contents from 4th row till first row below the fifth row.
示例/* program to print numeric pattern */#include<stdio.h>int main(){ int i,j,k; printf("numeric pattern 1"); printf("
"); printf("
"); for(i=1;i<=5;i++){ k = i; for(j=1;j<=i;j++){ printf("%d ", k); k += 5-j; } printf("
"); } printf("
"); printf("numeric pattern 2"); printf("
"); printf("
"); for(i = 1;i<=5;i++){ for(j = i;j<5;j++){ printf(" "); } for(k = 1;k<(i*2);k++){ printf("%d",k); } printf("
"); } for(i = 4;i>=1;i--){ for(j = 5;j>i;j--){ printf(" "); } for(k = 1;k<(i*2);k++){ printf("%d",k); } printf("
"); } getch(); return 0;}
输出
以上就是编写一个在c语言中打印数字模式的程序的详细内容。
其它类似信息

推荐信息