Pattern 1; 2 3; 4 5 6; 7 8 9 10
9 views (last 30 days)
Show older comments
Cem Burak YALCIN
on 14 May 2020
Commented: Ameer Hamza
on 14 May 2020
Hello everyone, I wish you healthy days.
How can i do that pattern by using just 'for, if else or while command?
the question is that for example i input number 5, matlab giving me (4 5 6). When i input 7 matlab giving me ( 7 8 9 10)
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17...
Sorry for my bad english and thanks for your help
0 Comments
Accepted Answer
Ameer Hamza
on 14 May 2020
Edited: Ameer Hamza
on 14 May 2020
Try this. It uses the formula 
n = input('Input n: ');
a = ceil((-1+sqrt(1+8*n))/2);
y = ((a-1)*a/2+1):(a*(a+1)/2);
disp(y)
2 Comments
Ameer Hamza
on 14 May 2020
If this is a homework question, then you need to show some code and ask a question about a specific issue related to MATLAB. At least, you should develop an algorithm to create these numbers.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!