{"id":9189,"date":"2021-09-30T12:00:32","date_gmt":"2021-09-30T06:30:32","guid":{"rendered":"https:\/\/python-programs.com\/?p=9189"},"modified":"2021-11-22T18:39:30","modified_gmt":"2021-11-22T13:09:30","slug":"print-all-integers-that-arent-divisible-by-either-2-or-3-and-lie-between-1-and-50-in-cpp-and-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/print-all-integers-that-arent-divisible-by-either-2-or-3-and-lie-between-1-and-50-in-cpp-and-python\/","title":{"rendered":"Print all Integers that Aren\u2019t Divisible by Either 2 or 3 and Lie between 1 and 50 in C++ and Python"},"content":{"rendered":"
In the previous article, we have discussed about Allocating and deallocating 2D arrays dynamically in C++<\/a>. Let us learn how to Print all Integers that Aren\u2019t Divisible by Either 2 or 3 and Lie between 1 and 50 in C++ Program.<\/p>\n The task is to print all the numbers from 1 to 50 which are not divisible by 2 or 3 in C++ and Python.<\/p>\n Sample Output:<\/strong><\/p>\n Grab the opportunity to learn all effective java programming language concepts from basic to advance levels by practicing these Java Program Examples with Output<\/a><\/p>\n There are several ways to print all the numbers from 1 to 50 which are not divisible by 2 or 3 some of them are:<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation: <\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n In the previous article, we have discussed about Allocating and deallocating 2D arrays dynamically in C++. Let us learn how to Print all Integers that Aren\u2019t Divisible by Either 2 or 3 and Lie between 1 and 50 in C++ Program. The task is to print all the numbers from 1 to 50 which are …<\/p>\nThe numbers from 1 to 50 which are not divisible by 2 and 3 are:\r\nNumber = 1\r\nNumber = 5\r\nNumber = 7\r\nNumber = 11\r\nNumber = 13\r\nNumber = 17\r\nNumber = 19\r\nNumber = 23\r\nNumber = 25\r\nNumber = 29\r\nNumber = 31\r\nNumber = 35\r\nNumber = 37\r\nNumber = 41\r\nNumber = 43\r\nNumber = 47\r\nNumber = 49<\/pre>\n
Print all Integers that Aren\u2019t Divisible by Either 2 or 3 and Lie between 1 and 50 in C++ and Python<\/h2>\n
\n
Method #1: Using for loop in Python<\/h3>\n
\n
# Use a for loop and a range() function which iterates from 1 to 50.\r\nprint(\"The numbers from 1 to 50 which are not divisible by 2 and 3 are:\")\r\nfor numb in range(1, 51):\r\n # Then, using an if statement, determine whether the integer is\r\n # not divisible by both 2 and 3.\r\n if(numb % 2 != 0 and numb % 3 != 0):\r\n # If the number is not divisible by 2 and 3 then print it.\r\n print(\"Number = \", numb)\r\n<\/pre>\n
The numbers from 1 to 50 which are not divisible by 2 and 3 are:\r\nNumber = 1\r\nNumber = 5\r\nNumber = 7\r\nNumber = 11\r\nNumber = 13\r\nNumber = 17\r\nNumber = 19\r\nNumber = 23\r\nNumber = 25\r\nNumber = 29\r\nNumber = 31\r\nNumber = 35\r\nNumber = 37\r\nNumber = 41\r\nNumber = 43\r\nNumber = 47\r\nNumber = 49<\/pre>\n
Method #2: Using for loop in C++<\/h3>\n
\n
#include <iostream>\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n \/\/ Use for loop in Which starts from 1 and ends at 50\r\n \/\/ using the syntax : for (numb=1;numb<=50;numb++)\r\n cout << \"The numbers from 1 to 50 which are not \"\r\n \"divisible by 2 and 3 are:\"\r\n << endl;\r\n for (int numb = 1; numb <= 50; numb++) {\r\n \/\/ Then, using an if statement determine whether the\r\n \/\/ integer is not divisible by both 2 and 3.\r\n\r\n if (numb % 2 != 0 && numb % 3 != 0) {\r\n \/\/ If the number is not divisible by 2 and 3\r\n \/\/ then print it.\r\n cout << \"Number = \" << numb << endl;\r\n }\r\n }\r\n return 0;\r\n}<\/pre>\n
The numbers from 1 to 50 which are not divisible by 2 and 3 are:\r\nNumber = 1\r\nNumber = 5\r\nNumber = 7\r\nNumber = 11\r\nNumber = 13\r\nNumber = 17\r\nNumber = 19\r\nNumber = 23\r\nNumber = 25\r\nNumber = 29\r\nNumber = 31\r\nNumber = 35\r\nNumber = 37\r\nNumber = 41\r\nNumber = 43\r\nNumber = 47\r\nNumber = 49<\/pre>\n
Method #3: Using while loop in Python<\/h3>\n
\n
# Use a for loop and a range() function which iterates from 1 to 50.\r\nprint(\"The numbers from 1 to 50 which are not divisible by 2 and 3 are:\")\r\n# Take a integer variable\u00a0 say tempo which stores the lower limit (in this case it is 1)\r\ntempo = 1\r\n# Using while loop iterate from 1 to 51 by using the condition tempo <=50\r\nwhile(tempo <= 50):\r\n\r\n # Then, using an if statement, determine whether the integer is\r\n # not divisible by both 2 and 3.\r\n if(tempo % 2 != 0 and tempo % 3 != 0):\r\n # If the number is not divisible by 2 and 3 then print it.\r\n print('Number =', tempo)\r\n # Increment the value of tempo by 1\r\n tempo = tempo+1\r\n<\/pre>\n
The numbers from 1 to 50 which are not divisible by 2 and 3 are:\r\nNumber = 1\r\nNumber = 5\r\nNumber = 7\r\nNumber = 11\r\nNumber = 13\r\nNumber = 17\r\nNumber = 19\r\nNumber = 23\r\nNumber = 25\r\nNumber = 29\r\nNumber = 31\r\nNumber = 35\r\nNumber = 37\r\nNumber = 41\r\nNumber = 43\r\nNumber = 47\r\nNumber = 49<\/pre>\n
Method #4: Using while loop in C++<\/h3>\n
\n
#include <iostream>\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n \/\/ Use for loop in Which starts from 1 and ends at 50\r\n \/\/ using the syntax : for (numb=1;numb<=50;numb++)\r\n cout << \"The numbers from 1 to 50 which are not \"\r\n \"divisible by 2 and 3 are:\"\r\n << endl;\r\n \/\/ Take a integer variable\u00a0 say tempo which stores the\r\n \/\/ lower limit (in this case it is 1)\r\n int tempo = 1;\r\n \/\/ Using while loop iterate from 1 to 51 by using the\r\n \/\/ condition tempo <=50\r\n while (tempo <= 50) {\r\n \/\/ Then, using an if statement determine whether the\r\n \/\/ integer is not divisible by both 2 and 3.\r\n\r\n if (tempo % 2 != 0 && tempo % 3 != 0) {\r\n \/\/ If the number is not divisible by 2 and 3\r\n \/\/ then print it.\r\n cout << \"Number = \" << tempo << endl;\r\n }\r\n \/\/ Increment the value of tempo by 1\r\n tempo = tempo + 1;\r\n }\r\n return 0;\r\n}<\/pre>\n
The numbers from 1 to 50 which are not divisible by 2 and 3 are:\r\nNumber = 1\r\nNumber = 5\r\nNumber = 7\r\nNumber = 11\r\nNumber = 13\r\nNumber = 17\r\nNumber = 19\r\nNumber = 23\r\nNumber = 25\r\nNumber = 29\r\nNumber = 31\r\nNumber = 35\r\nNumber = 37\r\nNumber = 41\r\nNumber = 43\r\nNumber = 47\r\nNumber = 49<\/pre>\n
\n
\nthe Least Significant Digit of the Entered Integer at One\u2019s Place<\/a><\/li>\n