Right triangle star pattern program

Right triangle star pattern in c

#include<stdio.h>
#include<conio.h>
void main()
{
	int rows;
	printf("Enter the number of rows \n");
	scanf("%d",&rows);
	for(int i=0;i<rows;i++)
	{
		for(int j=0;j<=i;j++)
		{
			printf("* ");
		}
		printf("\n");
	}
	getch();
}

Output

Enter the number of rows
5
*
* *
* * *
* * * *
* * * * *

Right triangle star pattern in c++

#include<iostream>
#include<conio.h>
using namespace std;
class RightTriangleStarPattern
{
public:
	void Show()
	{
    int rows;
	cout<<"Enter the number of rows \n";
	cin>>rows;
	for(int i=0;i<rows;i++)
	{
		for(int j=0;j<=i;j++)
		{
			cout<<"* ";
		}
		cout<<endl;
	}
	}
};
void main()
{
	RightTriangleStarPattern r;
	r.Show();
	getch();
}

Output

Enter the number of rows
6
*
* *
* * *
* * * *
* * * * *
* * * * * *

Right triangle star pattern in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RightTriangleStarPattern
{
    class Program
    {
        public void Show(int rows)
        {
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    Console.Write("* ");
                }
                Console.WriteLine();
            }
        }
        static void Main(string[] args)
        {
            Program p1 = new Program();
            Console.WriteLine("Enter the number of rows");
            int input = Convert.ToInt32(Console.ReadLine());
            p1.Show(input);
            Console.ReadLine();
        }
    }
}

Output

Enter the number of rows
7
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *

Right Triangle star pattern in java

import java.util.*;
class RightTrianglestarpattern
{
	public void Show(int rows)
	{
	 for(int i=0;i<rows;i++)
	 {
		 for(int j=0;j<=i;j++)
		 {
		  System.out.print("* ");
		 }
	  System.out.println();
	 }
	}
}
class examples
{
public static void main(String[] args)
	{
	RightTrianglestarpattern s=new RightTrianglestarpattern();
	Scanner sc=new Scanner(System.in);
	System.out.println("Enter the number of rows");
	int input=sc.nextInt();
	s.Show(input);
    }
}

Output

Enter the number of rows
8
* 
* * 
* * * 
* * * * 
* * * * * 
* * * * * * 
* * * * * * * 
* * * * * * * *

Write a comment


Name Email Message