算法接受打印左右箭头图案的行数.
print upper part of the arrow with stars patternsprint inverted right triangle with stars patternsprint bottom part of the arrow with stars patternsprint the right triangle with stars patterns
示例/*program to print the left and right arrow pattern*/#include<stdio.h>int main() { int r, c, rows; //left arrow pattern int r1, c1, rows1; //right arrow pattern clrscr(); printf("enter number of rows to print the left arrow pattern: "); scanf("%d", &rows); printf("
"); printf("the left arrow pattern is:"); printf("
"); for(r=1; r<rows; r++){ for(c=1; c<=(rows-r); c++){ printf(" "); } for(c=r;c<=rows; c++){ printf("*"); } printf("
"); } for(r=1; r<=rows; r++){ for(c=1; c<r; c++){ printf(" "); } for(c=1; c<=r; c++){ printf("*"); } printf("
"); } printf("enter number of rows to print the right arrow pattern: "); scanf("%d", &rows1); printf("
"); printf("the right arrow pattern is:"); printf("
"); for(r1=1; r1<rows1; r1++){ for(c1=1; c1<=(2*r1-2); c1++){ printf(" "); } for(c1=r1; c1<=rows1; c1++){ printf("*"); } printf("
"); } for(r1=1; r1<=rows1; r1++){ for(c1=1; c1<=(2*rows1 - 2*r1); c1++){ printf(" "); } for(c1=1; c1<=r1; c1++){ printf("*"); } printf("
"); } getch(); return 0;}
输出
以上就是在c语言中编写一个打印右箭头和左箭头图案的程序的详细内容。
