用数组,nXn矩形主对角线副对角线的和,n是从键盘输入的,怎么求!新手

qq_LeeMeYang_0
浏览 1553回答 1
1回答

望远

#include<stdio.h> void main( ) { int i,j,n; int arr[10][10],sum1=0,sum2=0; printf("请输入一个正整数n:"); scanf("%d",&n); printf("请输入一个%d*%d的矩阵:\n",n,n); for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d",&arr[i][j]); for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(i==j)//主对角线 sum1+=arr[i][j]; if(i+j==n-1)//副对角线 sum2+=arr[i][j]; } } printf("主对角线之和:%d  副对角线之和: %d\n",sum1,sum2); }

慕瓜9220888

ZUPKDNEEVHCBNGFJQUYCSONELPCIGWSHISZKABKQJBSCDXONTZWNQBLOKJZJDOFOWMIDAEYPLWCCBBJWDLWIUHOJPWVRONWVGMADENTLWXJJEMVCMWNHYRMRLYPQZPMHGPBZGGDPJILALVWMNREDWOWXOLWVYKKBVWKYMSEFPMWOMSBHIVDAWBQNWGRRZNYEDJSFZNIAPGJGUKHVWPSYOAULHGPGPRPWOQTNMISECCKFHRQRBISUWFLKLOZPTEDNRMJMWRCIYJGABLBUGZPPWQAUSLHDNJQBTBXDHOQQUWXVHXHBLPDIIIKBFCDNIFOIMUJHKPCMPHLQMOJZJMNCQVNJZCJHYIXKIIELTKYCBGAWJHFUTSXHNNLZDOTOELHTQYTLKUDQYGDECVANUVMUVEPIMWEOOJCGMLYCPXNWYLNNUECUUYLBKQUSCDHXVUYSZEXIEDDANBLLPSLCPDDKRHAJMNUEYLPJFEOPBPGVIYEVNXOHHAJWMAQHKGOLGYZTXXSRXDDHOYZXGEAHOIZCZIIXOCPNEIODWGABBNVUKWGNAEXRNDEVFKEBMHXGKNVFLBAGPMNKOGAKZFFCDQDSYRJXHLAVPIRNLFFDVGWSHISCNIMCSLDRFISGGRDEELJMPVEQXULMUSIENXIWEEIILHRVULZNGAAUIZDPKGISIZWKWXNJSQDEYRPVHQDGNHQBUJFGXHLKSRGTNNELPOL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