C 语言中打印左右箭头模式的程序
程序描述
打印左右箭头模式
算法
接受要打印左右箭头模式的行数。
Print Upper Part of the Arrow with Stars Patterns Print Inverted Right Triangle with Stars Patterns Print Bottom Part of the Arrow with Stars Patterns Print 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;
}输出


广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP