Effacer les filtres
Effacer les filtres

fprintf and \n (pyramid of numbers)

1 vue (au cours des 30 derniers jours)
yonatan friedman
yonatan friedman le 31 Déc 2019
clc; clear;
n = 6;
j = [];
for i = 1 : n
for j = i:n
fprintf('%d',i:j)
fprintf('\n')
end
end
~~~~~~~~~~~~~~~~~~
i want to do pyramid of numbers
for example n = 6
the output is :
1
23
456
  1 commentaire
dpb
dpb le 31 Déc 2019
Use fixed-width fields...

Connectez-vous pour commenter.

Réponses (1)

Maadhav Akula
Maadhav Akula le 3 Jan 2020
The following code might be helpful:
clc; clear;
n = 3;
i = 1;
j = 1;
l = 1;
while l<=n
while j<=i && l<=n
fprintf('%d',l)
l = l + 1;
j = j + 1;
end
fprintf('\n')
i = i + 1;
j = 1;
end
Hope this helps!

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by