patternprogram_79 softethics

Pattern 79

C

#include <stdio.h>
int main()
{

  int i,j,k;


  int d1=1; // for printing

  int n=4; //size

  int d2=(n*n)+1;

  for(i=n; i>=1; i--)
  {
    /* for 2nd part */
    for(k=1; k<=i; k++)
    {
      printf("%d ",d2);
      d2++;
    }
    d2--;  // decrement to get last printed value

    d2=d2-((i-1)*2); // used to set next print value

    printf("\n");
  }
}

C++

#include <iostream.h>
int main()
{

 


 int d1=1; // for printing

 int n=4; //size

 int d2=(n*n)+1; 

 for(int i =n;i>=1;i--)
 {
  /* for 2nd part */
  for(int k =1;k<=i;k++)
  {
   cout<<d2<<" ";
   d2++;
  }
  d2--;  // decrement to get last printed value

  d2=d2-((i-1)*2); // used to set next print value

  cout<<endl;
 }
 return 0;
}

Java

  class PatternProg
  {
   public static void main (String args[])
   {

    int i;
    int j;
    int k;


    int d1 = 1; // for printing

    int n = 4; //size

    int d2 = (n * n) + 1;

    for (i = n;i >= 1;i--)
    {
     /* for 2nd part */
     for (k = 1;k <= i;k++)
     {
      System.out.print(d2+" ");
      d2++;
     }
     d2--; // decrement to get last printed value

     d2 = d2 - ((i - 1) * 2); // used to set next print value

     System.out.println();
    }
    
   }
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int i;
    int j;
    int k;

    int d1 = 1; // for printing

    int n = 4; //size

    int d2 = (n * n) + 1;
    /* for 2nd part */

    for (i = n; i >= 1; i--)
    {

      for (k = 1; k <= i; k++)
      {
        Console.Write(d2 + " ");
        d2++;
      }
      d2--; // decrement to get last printed value

      d2 = d2 - ((i - 1) * 2); // used to set next print value

      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

n = 4  # size
p = 1  # for printing
q = (n * n) + 1

for x in range(n, 0, -1):
    for y in range(1, x + 1):
        print(str(q) + " ", end="")
        q += 1
    q -= 1
    q = q - ((x - 1) * 2)
    print()
5 2 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments