#Day7- #100DaysChallenge- Matlab Loops| Printing Special Character Pattern
#Day7- Printing Special Character Pattern
Task: Print the given character (maybe special character or alphabets or numeric) for the given number of times.
For example, If it is a first-line then print the character one time if it is second line print the character two times,as line increases the characters in the particular line should also increase accordingly.
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those
x=8
special_character_pattern(x,'G')
G
GG
GGG
GGGG
GGGGG
GGGGGG
GGGGGGG
GGGGGGGG
Matlab Code:
function special_character_pattern(x,y)
%x
=Number of lines
%y character like * & ^ % $ # @ ! or any
numeric or aplhabets with in ''
for i=1:1:x
for j=1:1:i
fprintf(y);
end
fprintf('\n');
end
Sample Input and Output
x=8;
>> special_character_pattern(x,'G')
G
GG
GGG
GGGG
GGGGG
GGGGGG
GGGGGGG
GGGGGGGG
>> special_character_pattern(8,'#')
#
##
###
####
#####
######
#######
########
>> special_character_pattern(10,'5')
5
55
555
5555
55555
555555
5555555
55555555
555555555
5555555555
No comments