Algorithm for Right Angled Triangle:
step 1: Set i= 0,j 0, row=0,osc=0,var=0
step 2: Read row
step 3: Move to new line
step4: If (row>O) then execute following steps else goto step-23
step 5: Initialize isc=0
step 6: Print “*”
step 7: Initialize i=2
step 8: Repeat through step-17while (i<row)
step 9: Print “*”
step l0: Initialize j=isc
step 11: Repeat through step-13 while(j>0)
step 12: Print one space
step 13: j=j-1
step 14: Print “*”
step 15: isc=isc+ 1
step 16: osc=osc-1
step 17: I=i+ 1
step 18: If(row!=1then execute following steps else goto step-23
step 19: Initialize l=1
step 20: Repeat through step-22 while (l<=row)
step 21: Print “*”
step 22:l=l+1
step 23: Exit
Here is the Java Example for Right Angled Triangle:
import java.util.*;
class RightAngledTriangle
{
public static void main(String s[])
{
int i,j,row,isc,osc,var;
i=j=row=osc=var=0;
Scanner read=new Scanner(System.in);
System.out.print("Enter number of Rows : ");
row=read.nextInt();
System.out.println("\n");
if(row>0)
{
System.out.print("\t");
isc=0;
System.out.println("*");
for(i=2;i<row;i++)
{
System.out.print("\t");
System.out.print("*");
for(j=isc;j>0;j--)
System.out.print(" ");
System.out.println("*");
isc++;
osc--;
}
if(row!=1)
{
System.out.print("\t");
for(int l=1;l<=row;l++)
System.out.print("*");
}
}
System.out.println("");
}
}