C 练习实例38
C 语言教程
· 2019-02-21 21:28:35
题目:求一个3*3矩阵对角线元素之和
程序分析:利用双重for循环控制输入二维数组,再将a[i][i]累加后输出。
实例
// Created by www.codercto.com on 15/11/9.
// Copyright © 2015年 码农教程. All rights reserved.
//
#include<stdio.h>
#define N 3
int main()
{
int i,j,a[N][N],sum=0;
printf("请输入矩阵(3*3):\n");
for(i=0;i<N;i++)
for(j=0;j<N;j++)
scanf("%d",&a[i][j]);
for(i=0;i<N;i++)
sum+=a[i][i];
printf("对角线之和为:%d\n",sum);
return 0;
}
以上实例输出结果为:
请输入矩阵(3*3): 1 2 3 4 5 6 7 8 9 对角线之和为:15
点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html
APIs
Daniel Jacobson、Greg Brail、Dan Woods / O'Reilly Media / 2011-12-24 / USD 24.99
Many of the highest traffic sites get more than half of their traffic not through the browser but through the APIs they have created. Salesforce.com (more than 50%) and Twitter (more than 75% fall int......一起来看看 《APIs》 这本书的介绍吧!