为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C
qq_LeeMeYang_0 2016-12-03 15:04:47
查看完整描述

1 回答

?
望远

TA贡献1017条经验 获得超1032个赞

#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);		
	
}

//img1.sycdn.imooc.com//5842806800018c6204080187.jpg

查看完整回答
2 反对 回复 2016-12-03
?
慕瓜9220888

TA贡献868条经验 获得超0个赞

ZUPKDNEEV

HCBNGFJQU

YCSONELPC

IGWSHISZK

ABKQJBSCD

XONTZWNQB

LOKJZJDOF

OWMIDAEYP

LWCCBBJWD

LWIUHOJPW

VRONWVGMA

DENTLWXJJ

EMVCMWNHY

RMRLYPQZP

MHGPBZGGD

PJILALVWM

NREDWOWXO

LWVYKKBVW

KYMSEFPMW

OMSBHIVDA

WBQNWGRRZ

NYEDJSFZN

IAPGJGUKH

VWPSYOAUL

HGPGPRPWO

QTNMISECC

KFHRQRBIS

UWFLKLOZP

TEDNRMJMW

RCIYJGABL

BUGZPPWQA

USLHDNJQB

TBXDHOQQU

WXVHXHBLP

DIIIKBFCD

NIFOIMUJH

KPCMPHLQM

OJZJMNCQV

NJZCJHYIX

KIIELTKYC

BGAWJHFUT

SXHNNLZDO

TOELHTQYT

LKUDQYGDE

CVANUVMUV

EPIMWEOOJ

CGMLYCPXN

WYLNNUECU

UYLBKQUSC

DHXVUYSZE

XIEDDANBL

LPSLCPDDK

RHAJMNUEY

LPJFEOPBP

GVIYEVNXO

HHAJWMAQH

KGOLGYZTX

XSRXDDHOY

ZXGEAHOIZ

CZIIXOCPN

EIODWGABB

NVUKWGNAE

XRNDEVFKE

BMHXGKNVF

LBAGPMNKO

GAKZFFCDQ

DSYRJXHLA

VPIRNLFFD

VGWSHISCN

IMCSLDRFI

SGGRDEELJ

MPVEQXULM

USIENXIWE

EIILHRVUL

ZNGAAUIZD

PKGISIZWK

WXNJSQDEY

RPVHQDGNH

QBUJFGXHL

KSRGTNNEL

POLHXBLCZ

PUJJIPTAX

YWHDZHBSC

MNWCWGHRR

YBLRKAHIU

FTZVXBYSZ

NPONLFCGA

LNWBBTRVL

PKGFEPVCG

XGMIPTBPT

DXHWMXECG

JOKGFCQNH

UPYODKLMM

LKGICCDLV

FLYQJKULV

AEKQCNOVG

CHJPOVGNQ

QUTPLVWTN

GRDJPQXEC

UJYODKCWN

CGZSMQBGK

GKTPYMAUK

UCACFMTRF

HSHPEBPWT

CDIBRYYST

NIHJMJDKR

RGZOERCPO

BVVFKFVPD

UVYXAHXRQ

MCZFETKUO

SNTZFSQAH

YMAVBESGL

ZUNUUAYRS

QFLRJAAOI

JDGXDRREV

EIYOQKEVW

MHTJMMDXY

WFBOALFPW

VTWVRJXXH

RWBRXWAHR

DSEKUWDNX

LWETWAABF

FUHAJDCQH

WUKGVPWGX

MRUQZJALW

CEQZYZWKU

BVATSJDQX

IDGPBVMMH

TYKJZZAXO

JMEDQBLSC

MXDZFCVIZ

USYNGNQEY

BTSPSJJSC

GBKHLUMQO

ZTGYRCCAK

SGCIUUVLA

VXKTQEUVP

LPFOUOFPC

ZNAWPCNAB

OSYBTXROQ

YDCBHBPDD

SFPFOPTAO

DHSBNOOVP

GUDZPPDBI

KSAWPQQXL

OPXGNLCQW

SDJXQXEBF

SQQLVLPNQ

JYGFBOOSJ

BVNPMMMJU

KSBAWENUS

OMIVWJDQH

JYBKDXUYL

NRHUXFWWL

LGLRAFZQJ

SDWHAKKYH

GUUGFTPST

WICSVGGXS

QYIEKKRVP

SJPOERVCM

AKUTFTQOM

LJYIRSWXX

XBNNGWAEL

UMJYKEBVT

XYUXGRLIC

HZIJSZRLM

JOUGUKOYP

CNJBAUMGA

LGJSBISTK

UYEFYFJDQ

VXQWBDIYJ

WRWPMCNUX

GLXNWKSST

TYNZSVWQH

QKKTIQAHK

PXLEUYFLP

ARXWLCGOZ

BLHHNARSP

YEOKTEOIR

LWSIRKBBI

查看完整回答
反对 回复 2021-10-21
  • 1 回答
  • 0 关注
  • 1552 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信