patternprogram_41 softethics

Pattern 41

C

#include <stdio.h>
int main()
{
  int i,j;
  int n=1;

  for(i=1; i<=4; i++)
  {
    for(j=1; j<=i; j++)
    {
      printf("%3d",n);
      n++;
    }
    printf("\n");
  }
  return 0;
}

C++

 #include <iostream.h>
 
 int main()
 {
 int i,j;
 int n=1;
 
 
 
 for(int i =1; i<=4; i++)
 {
  for(int j =1; j<=i; j++)
  {
   cout<<n;
   n++;
  }
  cout<<endl;
 }
  return 0;
 }

Java

     class PatternProg
     {
     public static void main(String a[])
     {
     int i;
     int j;
     int n = 1;
 
     for (i = 1; i <= 4; i++)
     {
      for (j = 1; j <= i; j++)
      {
       System.out.print(n);
       n++;
      }
      System.out.print("\n");
     }
 
     }
 }

C#

using System;

class PatternProg
{
  public static void Main(string[] a)
  {
    int i;
    int j;
    int n = 1;

    for (i = 1; i <= 4; i++)
    {
      for (j = 1; j <= i; j++)
      {
        Console.Write(n);
        n++;
      }
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

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