当前位置:网站首页>Find the sum of the elements of each row of the matrix
Find the sum of the elements of each row of the matrix
2022-07-03 14:15:00 【Study hard 867】
This question requires the preparation of procedures , Find a given m×n The sum of the elements of the matrix .
Input format :
The first line of input gives two positive integers m and n(1≤m,n≤6). And then m That's ok , Each line gives n It's an integer , meanwhile
Space off .
Output format :
Each row outputs the sum of the elements of the corresponding matrix row .
sample input :
3 2
6 3
1 -8
3 12
sample output :
9
-7
15Code :
#include <stdio.h>
int main(){
int lie,hang,sum=0;
scanf("%d%d",&hang,&lie);
int a[hang][lie];
int i,j;
for(i=0;i<hang;i++){
for(j=0;j<lie;j++)scanf("%d",&a[i][j]);
}
for(i=0;i<hang;i++){
for(j=0;j<lie;j++){
sum=a[i][j]+sum;
}
printf("%d\n",sum);
sum=0;
}
}
边栏推荐
猜你喜欢

Understanding of closures

Exercise 10-1 calculate the sum of 1 to n using recursive functions

牛客网:过河卒

protobuf与grpc

Exercise 6-1 classify and count the number of characters

JS Part 2

28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;

Interface for querying IP home

中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿

Vite project commissioning
随机推荐
How to delete an attribute or method of an object
Exercise 6-2 using functions to sum special A-string sequences
战略、战术(和 OKR)
Solve the problem of dormitory router campus network sharing login
常见问题之PHP——ldap_add(): Add: Undefined attribute type in
7-4 BCD decryption (10 points)
Raft agreement
Interface for querying IP home
Example analysis of QT learning 18 login dialog box
JS input number and standard digit number are compared. The problem of adding 0 to 0
[Jilin University] information sharing of postgraduate entrance examination and re examination
修改数据库中的记录为什么报这个错
Similarities and differences of sessionstorage, localstorage and cookies
Eight sorts
js 2023. String pair equal to the target string after connection
Metal organic framework MOFs loaded with non steroidal anti-inflammatory drugs | zif-8 wrapped Prussian blue loaded quercetin (preparation method)
必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
Leetcode(4)——尋找兩個正序數組的中比特數
编程语言:类型系统的本质
7-17 crawling worms (break exercise)