1
2 3
4 5 6
7 8 9 10
10 11 12 13 14
Here, we have a basic program example to print a right angled triangle where numbers are increased by 1 using different languages. This program is created in c language, c++, Java, and Python.
Code to print right angled triangle in C language
#include <stdio.h>
void main()
{
int i,j,rows, k=1;
printf("Input number of rows : ");
scanf("%d",&rows);
for(i=1;i<=rows;i++)
{
for(j=1;j<=i;j++)
printf("%d ",k++);
printf("\n");
}
}
Code to print right angled triangle in C++ language
#include <iostream>
using namespace std;
int main() {
int i,j,rows, k=1;
cout<<"Input number of rows : ";
cin>>rows;
for(i=1;i<=rows;i++)
{
for(j=1;j<=i;j++)
cout<<" "<<k++;
cout<<"\n";
}
}
Code to print right angled triangle in Python language
k=1
rows = int(input("Input number of rows : "))
for i in range (1, rows+1):
for j in range (1, i+1):
print(" ",k, end='')
k=k+1
print()
Code to print right angled triangle in Java language
import java.util.*;
public class pattern {
public static void main(String[] args) {
int i,j,rows, k=1;
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(" " + k++);
System.out.print("\n");
}
}
}