X^n calculation

11 vues (au cours des 30 derniers jours)
ceren uçak
ceren uçak le 1 Juin 2021
Commenté : James Tursa le 1 Juin 2021
Calculate the n th power of a given number with loops

Réponses (1)

Asmit Singh
Asmit Singh le 1 Juin 2021
%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 commentaire
James Tursa
James Tursa le 1 Juin 2021
@Asmit Singh Please do not post complete answers to homework questions.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by