当前位置:网站首页>Classic examples of C language - use 4 × The matrix displays all integers from 1 to 16 and calculates the sum of each row, column, and diagonal
Classic examples of C language - use 4 × The matrix displays all integers from 1 to 16 and calculates the sum of each row, column, and diagonal
2022-07-24 00:26:00 【Blue_ lan18】
Write a program , Require users ( In any order ) Input from 1 To 16 All integers of , And then use 4×4 Show them in the form of a matrix , Then calculate each line 、 The sum of each column and each diagonal :
# include <stdio.h>
int main()
{
int a11, a12, a13, a14;// Define the first line of numbers
int a21, a22, a23, a24;
int a31, a32, a33, a34;
int a41, a42, a43, a44;
int rowSum1 = 0, rowSum2 = 0, rowSum3 = 0, rowSum4 = 0;// Calculate the sum of each line of numbers
int columnSum1 = 0, columnSum2 = 0, columnSum3 = 0, columnSum4 = 0;// Calculate the sum of each column of numbers
int DiagonalSum1 = 0, DiagonalSum2 = 0;// Calculate the sum of the numbers on each diagonal
printf("Enter the numbers from 1 to 16 in any order: ");
scanf("%d%d%d%d", &a11, &a12, &a13, &a14);
scanf("%d%d%d%d", &a21, &a22, &a23, &a24);
scanf("%d%d%d%d", &a31, &a32, &a33, &a34);
scanf("%d%d%d%d", &a41, &a42, &a43, &a44);
printf("%5d %5d %5d %5d\n", a11, a12, a13, a14);
printf("%5d %5d %5d %5d\n", a21, a22, a23, a24);
printf("%5d %5d %5d %5d\n", a31, a32, a33, a34);
printf("%5d %5d %5d %5d\n", a41, a42, a43, a44);
rowSum1 = a11 + a12 + a13 + a14;
rowSum2 = a21 + a22 + a23 + a24;
rowSum3 = a31 + a32 + a33 + a34;
rowSum4 = a41 + a42 + a43 + a44;
columnSum1 = a11 + a21 + a31 + a41;
columnSum2 = a12 + a22 + a32 + a42;
columnSum3 = a13 + a23 + a33 + a43;
columnSum4 = a14 + a24 + a34 + a44;
DiagonalSum1 = a11 +a22 + a33 + a44;
DiagonalSum2 = a14 +a23 + a32 + a41;
printf("rowSums: %5d %5d %5d %5d\n", rowSum1, rowSum2, rowSum3, rowSum4);
printf("columnSums: %5d %5d %5d %5d\n", columnSum1, columnSum2, columnSum3, columnSum4);
printf("DiagonalSums: %5d %5d\n", DiagonalSum1, DiagonalSum2);
return 0;
}
边栏推荐
- Take stock of 10 new layer1 to prepare for the next bull market
- AWS Part 4 one machine and one secret
- 高数_第2章多元函数微分学__偏导数的几何应用_空间曲线的切线与法平面
- A lot of happiness in learning
- Educational Codeforces Round 132 (Rated for Div. 2)(A-D)
- July 23, 2022 - mapper file description
- vulnhub wpwn: 1
- Distributed cap principle
- 书写SQL必养成的好习惯
- Gbase 8C session information function (II)
猜你喜欢

NGFW portal authentication experiment

The prediction of domestic AI protein structure reproduced a breakthrough and solved the 3D structure with a single sequence. Peng Jian's team: "the last piece of puzzle since alphafold2 has been comp

vulnhub wpwn: 1

Application of encryption technology

Flutter | specifies the type of page return value

iNFTnews | 呵护“雪山精灵”,42VERSE“数字生态保护”公益项目即将盛启

泛型机制和增强for循环

Implementation of singleton mode in C #

高数_第1章空间解析几何与向量代数__两点距

北峰通信亮相中国(厦门)应急展|智能化通信手段强势吸睛!
随机推荐
Inftnews | protect the "Snow Mountain Spirit", and the 42verse "digital ecological protection" public welfare project is about to start
Generic mechanism and enhanced for loop
【Android Kotlin】Property、Getter 和 Setter
iNFTnews | 呵护“雪山精灵”,42VERSE“数字生态保护”公益项目即将盛启
Distributed cap principle
MySQL client to server character set conversion
docker 拉取redis镜像 并运行
What are blue-green deployment, Canary release and a/b test
Implementation of singleton mode in C #
Educational Codeforces Round 132 (Rated for Div. 2)(A-D)
The universal esp32c3 configures partition tables based on the Arduino ide framework
Docker builds sonarqube, mysql5.7 environment
Reverse linked list drawing demonstration
GBase 8c 会话信息函数(六)
Résumé du websocket minier
PHP implements stripe subscription
【电赛训练】非接触物体尺寸形态测量 2020年电赛G题
Jenkins uses sonarqube to build pipeline code review project
数仓数据标准详解-2022
Tencent will close the "magic core". Is there any resistance to the development of digital collections?