patternprogram_56 softethics

Pattern 56

C

/*

Interesting fact about this pattern :-

The last value(bottom-right corner) of the pattern is equal
              to the sum of all numbers from 1 to n.

e.g.

1
2 6
3 7 10
4 8 11 13
5 9 12 14 15


last value is 15, which is equal to 1+2+3+4+5

*/


#include<stdio.h>

int main()
{

  int n=10;// size

  int i,j,k;

  for(i=1; i<=n; i++)
  {
    k = i;

    for(j=1; j<=i; j++)
    {
      printf("%2d ",k);
      k=k+(n-j);
    }
    printf("\n");
  }

}

C++

 /*
 
 Interesting fact about this pattern :-
 
 The last value(bottom-right corner) of the pattern is equal 
                to the sum of all numbers from 1 to n.
 
 e.g.
 
 1
 2 6
 3 7 10
 4 8 11 13
 5 9 12 14 15
 
 
 last value is 15, which is equal to 1+2+3+4+5
 
 */
 
 
 #include<iostream.h>
 
 int main()
 {
 
 int n=10;// size
 
 
 
 for(int i =1;i<=n;i++)
 {
   k = i;
 
   for(int j =1;j<=i;j++)
  {
   cout<<k<<" ";
 
   k=k+(n-j);
  }
   cout<<endl;
 }
 
 }

Java

  /*
  * Interesting fact about this pattern :-
  *
  * The last value(bottom-right corner) of the pattern is 
                   equal to the sum of all
  * numbers from 1 to n.
  *
  * e.g.
  *
  * 1
  * 2 6
  * 3 7 10 
  * 4 8 11 13
  * 5 9 12 14 15
  *
  * last value is 15, which is equal to 1+2+3+4+5
  *
  */
 class PatternProg
 
     public static void main(String args[]) {
         int n = 10; // size
 
         int i;
         int j;
         int k;
 
   for (i = 1; i <= n; i++)
   {
     k = i;
     for (j = 1; j <= i; j++) 
     {
       System.out.printf("%2d ", k);
       k = k + (n - j);
     }
        System.out.print("\n");
     }
     }
 }

C#

using System;

/*
 * Interesting fact about this pattern :-
 *
 * The last value(bottom-right corner) of the pattern is equal to the sum of all
 * numbers from 1 to n.
 *
 * e.g.
 *
 * 1
 * 2 6
 * 3 7 10
 * 4 8 11 13
 * 5 9 12 14 15
 *
 * last value is 15, which is equal to 1+2+3+4+5
 *
 */
class PatternProg
{

  public static void Main()
  {
    int n = 10; // size

    int i;
    int j;
    int k;

    for (i = 1; i <= n; i++)
    {
      k = i;
      for (j = 1; j <= i; j++)
      {
        Console.Write("{0,2:D} ", k);
        k = k + (n - j);
      }
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

n = 5  # size
for x in range(1, n + 1):
    k = x
    for y in range(1, x + 1):
        print(str(k) + " ", end="")
        k = k + (n - y)
    print()

"""
Interesting fact about this pattern:

The last last value (botton-right corner) of the pattern is equal to the sum of all numbers from 1 to n.

e.g
Suppose, n=5

1 
2 6 
3 7 10 
4 8 11 13 
5 9 12 14 15 

last value is 15, that is equal to 1+2+3+4+5

"""
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments