您当前的位置: 首页 >  matlab

川川菜鸟

暂无认证

  • 2浏览

    0关注

    969博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

matlab刷题,由浅入深(3)

川川菜鸟 发布时间:2021-12-11 15:06:08 ,浏览量:2

文章目录
    • 题目
    • matlab解题

题目

求输入向量×的所有数字的总和

 Examples:

Input  x = [1 2 3 5]
Output y is 11

Input  x = [42 -1]
Output y i 41
matlab解题

函数:

function y = vecsum(x)
    y = sum(x);
    fprintf('y is %d',y);
end

主函数:

% 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

结果: 在这里插入图片描述

关注
打赏
1665165634
查看更多评论
立即登录/注册

微信扫码登录

1.7839s