1
12
123
1234
12345
Here, we have a basic program example to print right angled triangle with numbers using different languages. This program is created in c language, c++, Java, and Python.
Code to print right angled triangle with 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",j);
printf("\n");
}
}
Code to print right angled triangle with 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<<j;
cout<<"\n";
}
}
Code to print right angled triangle with 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(j , end='')
print()
Code to print right angled triangle with 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(j);
System.out.print("\n");
}
}
}