C语言打印镜像空心平行四边形程序
程序描述
它是一个四边形,其中两对对边平行。

平行四边形有六个重要的性质需要注意
- 对边全等 (AB = DC)。
- 对角相等 (D = B)。
- 邻角互补 (A + D = 180°)。
- 如果一个角是直角,则所有角都是直角。
- 平行四边形的对角线互相平分。
- 平行四边形的每条对角线都将其分成两个全等的
算法
- 从用户处接收行数和列数。将其存储在rows和cols变量中。
- 要遍历行,运行一个外循环,循环结构应类似于`for(r=1; r<=rows; r++)`。
- 要打印空格,运行一个内循环,循环结构为`for(c=1; c
- 打印星号以形成空心平行四边形,运行另一个内循环,循环结构类似于`for(c=1; c<=cols; c++)`。在此循环内,仅当`r==1`或`r==rows`或`c==1`或`c==cols`时才打印星号。
- 打印完一行的所有列后,换行,即打印换行符。
示例
// C program to print mirrored hollow parallelogram
#include <stdio.h>
int main(){
int rows,cols,r,c;
clrscr(); /*Clears the Screen*/
printf("Please enter the number of Rows: ");
scanf("%d", &rows);
printf("
");
printf("Please enter the number of Columns: ");
scanf("%d", &cols);
printf("
");
printf("The Mirrored Hollow Parallelogram is: ");
printf("
");
for(r = 1; r <= rows; r++){
// Display spaces
for(c = 1; c < r; c++) {
printf(" ");
}
// Display hollow parallelogram
for(c = 1; c <= cols; c++) {
if (r == 1 || r == rows || c == 1 || c == cols) {
printf("*");
}
else {
printf(" ");
}
}
printf("
");
}
getch();
return 0;
}输出


广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP