Pattern-21

 Pattern21


C Program
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n,i,j,k;
   printf("Enter the number of rows: ");
   scanf("%d",&n);
   for(i =1;i<=n; i++)
		{
			 k=i;
			for(j=1;j<=i;j++)
			{
				printf("%d ",k);
				k = k+(n-j);
			}
			printf("\n");
		}
}


Java Program
import java.util.Scanner;

public class Pattern_21 {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		System.out.print("Enter the number of rows:");
		int n = s.nextInt();
		for(int i =1;i<=n; i++)
		{
			int k=i;
			for(int j =1;j<=i;j++)
			{
				System.out.print(k+" ");
				k = k+(n-j);
			}
			System.out.println("");
		}

	}

}


Python Program
n = int(input("Enter numbe of rows: "))
for i in range(n):
    k=i+1
    for j in range(i+1):
            print(k, end=" ")
            k = k+(n-(j+1))
    print(" ")

0 Comments:

Post a Comment