CODY Contest 2020 MATLAB Onramp Practice 全15题

第一题 Problem 1. Times 2 - START HERE

Try out this test problem first.

Given the variable x as your input, multiply it by two and put the result in y.

Examples:

Input x = 2

Output y is 4

 

Input x = 17

Output y is 34

返回输入值的二倍

function y = times2(x) % Do not edit this line.

  % Modify the line below so that the output y is twice the incoming value x

  y = 2*x;

  % After you modify the code, press the "Submit" button, and you're on your way.

end % Do not edit this line.

 第二题 Problem 44943. Calculate Amount of Cake Frosting

Given two input variables r and h, which stand for the radius and height of a cake, calculate the surface area of the cake you need to put frosting on (all around the sides and the top).

Return the result in output variable SA.

给定蛋糕的半径r和高度h,求需要进行糖霜处理的表面积。只包括顶部的底面积和周围的侧面积。底面积等于pi*r^2,侧面积等于2*pi*r*h。

function SA = func_frosting(r,h)
  SA = 2*pi*r*h+pi*r*r;
end

第三题 Problem 44944. Convert from Fahrenheit to Celsius

Given an input vector F containing temperature values in Fahrenheit, return an output vector C that contains the values in Celsius using the formula:

将华氏度转化为摄氏度,并且公式已经给出:

C = (F–32) * 5/9

直接把公式复制进去就行。

function C = temp_convert(F)
  C=(F-32) * 5/9;
end

第四题 Problem 44947. Find the Oldest Person in a Room

Given two input vectors:

  • name - user last names
  • age - corresponding age of the person

Return the name of the oldest person in the output variable old_name.

给定姓名数组和对应的年龄数组,返回年龄最大人的姓名。使用find函数和max函数对age进行操作然后索引name数组即可。

function old_name = find_max_age(name,age)
    old_name=name(find(age==max(age)));
end

第五题 Problem 44951. Verify Law of Large Numbers

If a large number of fair N-sided dice are rolled, the average of the simulated rolls is likely to be close to the mean of 1,2,...N i.e. the expected value of one die. For example, the expected value of a 6-sided die is 3.5.

Given N, simulate 1e8 N-sided dice rolls by creating a vector of 1e8 uniformly distributed random integers. Return the difference between the mean of this vector and the mean of integers from 1 

评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值