matlab刷题,由浅入深(3)
【摘要】
文章目录
题目matlab解题
题目
求输入向量×的所有数字的总和
Examples:
Input x = [1 2 3 5]
Output y is 11
Input x...
题目
求输入向量×的所有数字的总和
Examples:
Input x = [1 2 3 5]
Output y is 11
Input x = [42 -1]
Output y i 41
- 1
- 2
- 3
- 4
- 5
- 6
- 7
matlab解题
函数:
function y = vecsum(x)
y = sum(x);
fprintf('y is %d',y);
end
- 1
- 2
- 3
- 4
主函数:
% Use this area as a scratchpad to test code that you don't want to submit:
x =[1 2 3 4];
% Or call your function:
vecsum(x);
% Note this code will NOT be used for submit
- 1
- 2
- 3
- 4
- 5
结果:

文章来源: chuanchuan.blog.csdn.net,作者:川川菜鸟,版权归原作者所有,如需转载,请联系作者。
原文链接:chuanchuan.blog.csdn.net/article/details/121873597
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)