1
22
333
4444
55555
Here, we have a basic program example to print a right angled tringle with numbers repeating themselves in the row using different languages. This program is created in c language, c++, Java, and Python.
Code to print right angles triangle with repeated numbers in C language
#include <stdio.h>
void main()
{
int i,j,rows;
printf("Input number of rows : ");
scanf("%d",&rows);
for(i=1;i<=rows;i++)
{
for(j=1;j<=i;j++)
printf("%d",i);
printf("\n");
}
}
Code to print right angles triangle with repeated numbers in C++ language
#include <iostream>
using namespace std;
int main() {
int i,j,rows;
cout<<"Input number of rows : ";
cin>>rows;
for(i=1;i<=rows;i++)
{
for(j=1;j<=i;j++)
cout<<i;
cout<<"\n";
}
}
Code to print right angles triangle with repeated numbers in Python language
rows = int(input("Input number of rows : "))
for i in range (1, rows+1):
for j in range (1, i+1):
print(i , end='')
print()
Code to print right angles triangle with repeated numbers in Java language
import java.util.*;
public class pattern {
public static void main(String[] args) {
int i,j,rows;
System.out.println("Enter a positive integer: ");
Scanner s=new Scanner(System.in);
rows = s.nextInt();
for(i=1;i<=rows;i++)
{
for(j=1;j<=i;j++)
System.out.print(i);
System.out.print("\n");
}
}
}