X^n calculation

2 次查看(过去 30 天)
ceren uçak
ceren uçak 2021-6-1
Calculate the n th power of a given number with loops

回答(1 个)

Asmit Singh
Asmit Singh 2021-6-1
%Number is the base number
number = 5;
ans = 1;
% n is the power to which the number needs to be raised
n = 3;
while(n~=0)
ans = ans*number;
n=n-1;
end
  1 个评论
James Tursa
James Tursa 2021-6-1
@Asmit Singh Please do not post complete answers to homework questions.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by