Computer Science, asked by soubiyahenaya, 18 days ago

Write the program of the given pattern
14 11 8 5 2
11 8 5 2
8 5 2
5 2
2

Answers

Answered by anindyaadhikari13
2

Solution:

1) In Java.

public class Pattern{

   public static void main(String args[]){

       int i, j, n = 5;

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

           for(j=i;j>0;j--)

               System.out.print(3 * j - 1 + " ");

           System.out.println();

       }

   }

}

2) In Python

n = 5

for i in range(n, 0, -1):

   for j in range(i, 0, -1):

       print(3 * j - 1, end = ' ')

   print()

3) In C

#include <stdio.h>

int main() {

   int i, j, n = 5;

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

       for(j=i;j>0;j--)

           printf("%d ", 3 * j - 1);

       printf("\n");

   }

   return 0;

}

4) In C++

#include <iostream>

using namespace std;

int main() {

   int i, j, n = 5;

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

       for(j=i;j>0;j--)

           cout << 3 * j - 1 << " ";

       cout << endl;

   }

   return 0;

}

Refer to the attachment for output.

Attachments:
Similar questions