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

Search This Blog

Programming concept on Lower & upper triangular MATRIX

Lower Triangular MATRIX:

clc
clear all
close all
y=[];
for i=1:5
    for j=1:5
        if(i<j)
        y(i,j)=0;
        else
            y(i,j)=1;
        end
    end
end
disp(y);

EXPLANATION:



Output:

Upper Triangular MATRIX:

CODE:

clc
clear all
close all
y=[];
for i=1:5
    for j=1:5
        if(i>j)
        y(i,j)=0;
        else
            y(i,j)=1;
        end
    end
end

disp(y);


MATLAB code to print Hollo LowerTriangular Pattern:

clc
clear all
close all
for i=1:15
    for j=1:15
        if(i==1 || j==1 || i==15 || j==15)
            fprintf('*');
        elseif(i>=j)
            fprintf(' ');
        else
            fprintf('*');
        end
    end
        fprintf('\n');
end
 

OUTPUT:


No comments

Popular Posts

Followers