Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

#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

Click Here for Video Description

Join us on Telegram: https://t.me/matlabirawenJoin us on Facebook Group: https://www.facebook.com/groups/matlabcodes



No comments

Popular Posts

Followers