在C语言中编写一个程序,打印出以Z形状排列的平方矩阵

2023年 8月 27日 9.4k 0

/* Program to print a square matrix in Z form */
#include
int main(){
int rows, cols, r, c, matrix[10][10];
clrscr(); /*Clears the Screen*/
printf("Please enter the number of rows for the Square matrix: ");
scanf("%d", &rows);
printf("

");
printf("Please enter the number of columns for the Square matrix: ");
scanf("%d", &cols);
printf("

");
printf("Please enter the elements for the Matrix:

");
for(r = 0; r < rows; r++){
for(c = 0;c < cols;c++){
scanf("%d", &matrix[r][c]);
}
}
printf("The Z Form Elements in the Square Matrix are: ");
printf("

");
for(r = 0; r < rows; r++){
printf("%d\t ", matrix[0][r]);
}
for (r=1,c=cols-2;r=0;r++,c--){
printf("%d\t ", matrix[r][c]);
}
for (r = 1; r < cols; r++){
printf("%d\t ", matrix[cols-1][r]);
}
getch();
return 0;
}

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论