{"id":12256,"date":"2021-09-30T15:00:38","date_gmt":"2021-09-30T09:30:38","guid":{"rendered":"https:\/\/python-programs.com\/?p=12256"},"modified":"2021-11-22T18:34:27","modified_gmt":"2021-11-22T13:04:27","slug":"python-program-to-print-even-number-pattern","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-even-number-pattern\/","title":{"rendered":"Python Program to Print Even Number Pattern"},"content":{"rendered":"
Are you wondering how to seek help from subject matter experts and learn the Java language? Go with these Basic Java Programming Examples<\/a> and try to code all of them on your own then check with the exact code provided by expert programmers.<\/p>\n Given the number of rows, the task is to print Even Number Pattern in C, C++, and Python.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to print Even Number Pattern in C, C++, and Python.<\/p>\n Approach:<\/strong><\/p>\n 1) Python Implementation<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 2) C++ Implementation<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 3) C Implementation<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n 1) Python Implementation<\/strong><\/p>\n Give the number of rows as user input using int(input()) and store it in a variable.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 2) C++ Implementation<\/strong><\/p>\n Give the number of rows as user input using cin and store it in a variable.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 3) C Implementation<\/strong><\/p>\n Give the number of rows as user input using scanf and store it in a variable.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Are you wondering how to seek help from subject matter experts and learn the Java language? Go with these Basic Java Programming Examples and try to code all of them on your own then check with the exact code provided by expert programmers. Given the number of rows, the task is to print Even Number …<\/p>\nGiven number of rows = 10<\/pre>\n
20 \r\n20 18 \r\n20 18 16 \r\n20 18 16 14 \r\n20 18 16 14 12 \r\n20 18 16 14 12 10 \r\n20 18 16 14 12 10 8 \r\n20 18 16 14 12 10 8 6 \r\n20 18 16 14 12 10 8 6 4 \r\n20 18 16 14 12 10 8 6 4 2<\/pre>\n
Given number of rows = 6<\/pre>\n
12 \r\n12 10 \r\n12 10 8 \r\n12 10 8 6 \r\n12 10 8 6 4 \r\n12 10 8 6 4 2<\/pre>\n
Program to Print Even Number Pattern in C, C++, and Python<\/h2>\n
\n
Method #1: Using For Loop (Static Input)<\/h3>\n
\n
# Give the number of rows as static input and store it in a variable.\r\nnumberOfRows = 10\r\n# Take a variable and initialize it with 2*double the number of rows say lastnumb.\r\nlastnumb = 2*numberOfRows\r\n# Take another variable and initialize it with the lastnumb\u00a0say evennumb.\r\nevennumb = lastnumb\r\n# Loop from 1 to the number of rows using For loop.\r\nfor m in range(1, numberOfRows+1):\r\n # Initialize the evennumb with the\u00a0lastnumb.\r\n evennumb = lastnumb\r\n # Loop from 0 to the iterator value of the parent For loop using\r\n # another for loop(Nested For loop).\r\n for n in range(0, m):\r\n # Print the evennumb.\r\n print(evennumb, end=' ')\r\n # Reduce the evennumb\u00a0by 2.\r\n evennumb = evennumb-2\r\n\r\n # Print the Newline character after the end of the inner loop.\r\n print()\r\n<\/pre>\n
20 \r\n20 18 \r\n20 18 16 \r\n20 18 16 14 \r\n20 18 16 14 12 \r\n20 18 16 14 12 10 \r\n20 18 16 14 12 10 8 \r\n20 18 16 14 12 10 8 6 \r\n20 18 16 14 12 10 8 6 4 \r\n20 18 16 14 12 10 8 6 4 2<\/pre>\n
#include <iostream>\r\n#include <math.h>\r\nusing namespace std;\r\nint main()\r\n{\r\n\r\n \/\/ Give the number of rows as static input and store it\r\n \/\/ in a variable.\r\n int numberOfRows = 8;\r\n \/\/ Take a variable and initialize it with 2*double the\r\n \/\/ number of rows say lastnumb.\r\n int lastnumb = 2 * numberOfRows;\r\n\r\n \/\/ Take another variable and initialize it with the\r\n \/\/ lastnumb\u00a0say evennumb.\r\n int evennumb = lastnumb;\r\n \/\/ Loop from 1 to the number of rows using For loop.\r\n for (int m = 1; m <= numberOfRows; m++) {\r\n \/\/ Initialize the evennumb with the\u00a0lastnumb.\r\n evennumb = lastnumb;\r\n \/\/ Loop from 0 to the iterator value of the parent\r\n \/\/ For loop using\r\n \/\/ another for loop(Nested For loop).\r\n for (int n = 0; n < m; n++) {\r\n \/\/ Print the evennumb.\r\n cout << evennumb << \" \";\r\n\r\n \/\/ Reduce the evennumb\u00a0by 2.\r\n evennumb = evennumb - 2;\r\n }\r\n \/\/ Print the Newline character after the end of the\r\n \/\/ inner loop.\r\n cout << endl;\r\n }\r\n\r\n return 0;\r\n}<\/pre>\n
16 \r\n16 14 \r\n16 14 12 \r\n16 14 12 10 \r\n16 14 12 10 8 \r\n16 14 12 10 8 6 \r\n16 14 12 10 8 6 4 \r\n16 14 12 10 8 6 4 2<\/pre>\n
#include <stdio.h>\r\n\r\nint main()\r\n{\r\n\r\n \/\/ Give the number of rows as static input and store it\r\n \/\/ in a variable.\r\n int numberOfRows = 8;\r\n \/\/ Take a variable and initialize it with 2*double the\r\n \/\/ number of rows say lastnumb.\r\n int lastnumb = 2 * numberOfRows;\r\n\r\n \/\/ Take another variable and initialize it with the\r\n \/\/ lastnumb\u00a0say evennumb.\r\n int evennumb = lastnumb;\r\n \/\/ Loop from 1 to the number of rows using For loop.\r\n for (int m = 1; m <= numberOfRows; m++) {\r\n \/\/ Initialize the evennumb with the\u00a0lastnumb.\r\n evennumb = lastnumb;\r\n \/\/ Loop from 0 to the iterator value of the parent\r\n \/\/ For loop using\r\n \/\/ another for loop(Nested For loop).\r\n for (int n = 0; n < m; n++) {\r\n \/\/ Print the evennumb.\r\n printf(\"%d \", evennumb);\r\n\r\n \/\/ Reduce the evennumb\u00a0by 2.\r\n evennumb = evennumb - 2;\r\n }\r\n \/\/ Print the Newline character after the end of the\r\n \/\/ inner loop.\r\n printf(\"\\n\");\r\n }\r\n return 0;\r\n}<\/pre>\n
16 \r\n16 14 \r\n16 14 12 \r\n16 14 12 10 \r\n16 14 12 10 8 \r\n16 14 12 10 8 6 \r\n16 14 12 10 8 6 4 \r\n16 14 12 10 8 6 4 2<\/pre>\n
Method #2: Using For Loop (User Input)<\/h3>\n
\n
# Give the number of rows as user input using int(input()) and store it in a variable.\r\nnumberOfRows = int(input('Enter some random number of rows = '))\r\n# Take a variable and initialize it with 2*double the number of rows say lastnumb.\r\nlastnumb = 2*numberOfRows\r\n# Take another variable and initialize it with the lastnumb\u00a0say evennumb.\r\nevennumb = lastnumb\r\n# Loop from 1 to the number of rows using For loop.\r\nfor m in range(1, numberOfRows+1):\r\n # Initialize the evennumb with the\u00a0lastnumb.\r\n evennumb = lastnumb\r\n # Loop from 0 to the iterator value of the parent For loop using\r\n # another for loop(Nested For loop).\r\n for n in range(0, m):\r\n # Print the evennumb.\r\n print(evennumb, end=' ')\r\n # Reduce the evennumb\u00a0by 2.\r\n evennumb = evennumb-2\r\n\r\n # Print the Newline character after the end of the inner loop.\r\n print()\r\n<\/pre>\n
Enter some random number of rows = 10\r\n20 \r\n20 18 \r\n20 18 16 \r\n20 18 16 14 \r\n20 18 16 14 12 \r\n20 18 16 14 12 10 \r\n20 18 16 14 12 10 8 \r\n20 18 16 14 12 10 8 6 \r\n20 18 16 14 12 10 8 6 4 \r\n20 18 16 14 12 10 8 6 4 2<\/pre>\n
#include <iostream>\r\nusing namespace std;\r\nint main()\r\n{\r\n\r\n \/\/ Give the number of rows as user input using\r\n \/\/ int(input()) and store it in a variable.\r\n int numberOfRows;\r\n cin >> numberOfRows;\r\n \/\/ Take a variable and initialize it with 2*double the\r\n \/\/ number of rows say lastnumb.\r\n int lastnumb = 2 * numberOfRows;\r\n\r\n \/\/ Take another variable and initialize it with the\r\n \/\/ lastnumb\u00a0say evennumb.\r\n int evennumb = lastnumb;\r\n \/\/ Loop from 1 to the number of rows using For loop.\r\n for (int m = 1; m <= numberOfRows; m++) {\r\n \/\/ Initialize the evennumb with the\u00a0lastnumb.\r\n evennumb = lastnumb;\r\n \/\/ Loop from 0 to the iterator value of the parent\r\n \/\/ For loop using\r\n \/\/ another for loop(Nested For loop).\r\n for (int n = 0; n < m; n++) {\r\n \/\/ Print the evennumb.\r\n cout << evennumb << \" \";\r\n\r\n \/\/ Reduce the evennumb\u00a0by 2.\r\n evennumb = evennumb - 2;\r\n }\r\n \/\/ Print the Newline character after the end of the\r\n \/\/ inner loop.\r\n cout << endl;\r\n }\r\n\r\n return 0;\r\n}<\/pre>\n
6\r\n12 \r\n12 10 \r\n12 10 8 \r\n12 10 8 6 \r\n12 10 8 6 4 \r\n12 10 8 6 4 2 \r\n\r\n<\/pre>\n
#include <stdio.h>\r\nint main()\r\n{\r\n\r\n \/\/ Give the number of rows as user input using scanf and\r\n \/\/ store it in a variable.\r\n int numberOfRows;\r\n scanf(\"%d\", &numberOfRows);\r\n \/\/ Take a variable and initialize it with 2*double the\r\n \/\/ number of rows say lastnumb.\r\n int lastnumb = 2 * numberOfRows;\r\n\r\n \/\/ Take another variable and initialize it with the\r\n \/\/ lastnumb\u00a0say evennumb.\r\n int evennumb = lastnumb;\r\n \/\/ Loop from 1 to the number of rows using For loop.\r\n for (int m = 1; m <= numberOfRows; m++) {\r\n \/\/ Initialize the evennumb with the\u00a0lastnumb.\r\n evennumb = lastnumb;\r\n \/\/ Loop from 0 to the iterator value of the parent\r\n \/\/ For loop using\r\n \/\/ another for loop(Nested For loop).\r\n for (int n = 0; n < m; n++) {\r\n \/\/ Print the evennumb.\r\n printf(\"%d \", evennumb);\r\n\r\n \/\/ Reduce the evennumb\u00a0by 2.\r\n evennumb = evennumb - 2;\r\n }\r\n \/\/ Print the Newline character after the end of the\r\n \/\/ inner loop.\r\n printf(\"\\n\");\r\n }\r\n return 0;\r\n}<\/pre>\n
6\r\n12 \r\n12 10 \r\n12 10 8 \r\n12 10 8 6 \r\n12 10 8 6 4 \r\n12 10 8 6 4 2<\/pre>\n
\n