c语言中已知一矩阵求其四周元素之和

来源:百度知道 编辑:UC知道 时间:2024/05/29 20:26:09
e.g. 1 2 3 Sum=1+2+3+4+7+8+9+6=?这样的程序算法!!!
4 5 6
7 8 9
我说的是像这样的程序,而不是这个矩阵的程序啊
是对你输入的任何一个矩阵都能输出结果来的算法和程序
大哥,你会的话,帮帮我啊!!!老师整我,要程序,没有办法!!!

说明1:前面的....为缩进符,只为排版。

#include "stdio.h"
#include "conio.h"

main()
{
....int colnum = 0;
....int rownum = 0;
....int i = 0;
....int j = 0;
....int inputNum;
....int sum = 0;

....printf("Please input the colnum you want to count:");
....scanf ("%d",&colnum);
....printf("Please input the rownum you want to count:");
....scanf ("%d",&rownum);

....for(i = 0; i<colnum; i++){
........if(0 == i || colnum-1 == i){ /* the top line and the bottom line*/
............for(j=0;j<rownum; j++){
................printf("element[%d][%d]:",i+1,j+1);
................scanf("%d",&inputNum);
................sum += inputNum;
............}
........}else{
......../* the center part*/
......../*only count the first and the last element of the line*/
............for(j=0;j<row