今日练习cody之分享

Problem 5. Triangle Numbers

function t = triangle(n)
t=0;
 for i=1:n
    t=t+i;
 end
end

Problem 1035. Generate a vector like 1,2,2,3,3,3,4,4,4,4

function ans = your_fcn_name(x)
ans=[];
for i=1:x
    b=repmat(i,1,i);
    ans=[ans b];
end
end

Problem 23. Finding Perfect Squares

function b = isItSquared(a)
 for i=1:length(a) 
if ~isempty(find(a==(a(i))^2))
  b = true;
  break
else
  b = false;  
end
 end
end

Problem 1702. Maximum value in a matrix

function y = your_fcn_name(x)
  y = max(max(x));
end

Problem 1744. Make a Plot with Functions

function h = makeAPlot(x,y,color)
h=plot(x,y,color) ;
end

Problem 12. Fibonacci sequence

function f = fib(n)
  if n == 1 || n == 2
    f = 1;
else
    f = fib(n-1) + fib(n-2);
end

Problem 3056. Chess probability

function y = expected_score(elo1,elo2)
a=(1+10^((elo2-elo1)/400))^(-1);
y=round(a,3);
end

Problem 174. Roll the Dice!

function [x1,x2] = rollDice()
  x1 = randperm(6,1);
  x2 = randperm(6,1);
end

Problem 1087. Magic is simple (for beginners)

function m = magic_sum(n)
  a=magic(n);
  m=max(sum(a));
end

Problem 233. Reverse the vector

function y = reverseVector(x)
  y=x(end:-1:1);   
end

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值