CODY Contest 2020 Introduction to MATLAB 全24题(上)

 

第一题        Problem 8. Add two numbers

Given a and b, return the sum a+b in c.

返回两数之和。

function c = add_two_numbers(a,b)
  c = a+b;
end

第二题       Problem 3.Find the sum of all the numbers of the input vector

Find the sum of all the numbers of the input vector x.

Examples:

 

Input x = [1 2 3 5]

Output y is 11

 

Input x = [42 -1]

Output y is 41

返回向量所用元素之和,直接使用sum()即可。 

function ans = vecsum(x)
   sum(x)
end

注意,原本给的函数的返回变量为y,在此修改为ans,并在计算最终结果时不加分号,能够节省变量空间,很多题都可以这么优化。

第三题  Problem 1702. Maximum value in a matrix

Find the maximum value in

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值