{"id":25734,"date":"2021-12-04T09:20:05","date_gmt":"2021-12-04T03:50:05","guid":{"rendered":"https:\/\/python-programs.com\/?p=25734"},"modified":"2021-12-04T09:20:05","modified_gmt":"2021-12-04T03:50:05","slug":"python-program-to-find-nth-decagonal-number","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-nth-decagonal-number\/","title":{"rendered":"Python Program to Find nth Decagonal Number"},"content":{"rendered":"
Decagonal Number:<\/strong><\/p>\n A decagonal number is a figurate number that extends the triangle and square number concepts to the decagon (a ten-sided polygon). \u00a0The nth decagonal number counts the number of dots in a pattern of n nested decagons, each of which has a shared corner.<\/p>\n Formula to generate a Decagonal Number:<\/strong><\/p>\n Given a number and the task is to find the decagonal number of a given number.<\/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 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 <\/p>\n","protected":false},"excerpt":{"rendered":" Decagonal Number: A decagonal number is a figurate number that extends the triangle and square number concepts to the decagon (a ten-sided polygon). \u00a0The nth decagonal number counts the number of dots in a pattern of n nested decagons, each of which has a shared corner. Formula to generate a Decagonal Number: D(n) = 4*n^2 …<\/p>\nD(n) = 4*n^2 - 3*n<\/pre>\n
Given Number = 4<\/pre>\n
The decagonal number of a given number { 4 } = \r\n52<\/pre>\n
Given Number = 10<\/pre>\n
The decagonal number of a given number { 10 } = \r\n370<\/pre>\n
Program to Find nth Decagonal Number in Python<\/h2>\n
\n
Method #1: Using Mathematical Formula (Static Input)<\/span><\/h3>\n
\n
# Create a function say Find_DecagonalNum() which accepts the given number as an\r\n# argument and returns the decagonal number of the given number.\r\n\r\n\r\ndef Find_DecagonalNum(gvn_num):\r\n # Inside the function, calculate the decagonal number of a given number using the\r\n # above given mathematical formula and return it.\r\n return(4*gvn_num*gvn_num - 3*gvn_num)\r\n\r\n\r\n# Give the number as static input and store it in a variable.\r\ngvn_num = 4\r\n# Pass the given number to the Find_DecagonalNum() function store it in another\r\n# variable.\r\nrslt = Find_DecagonalNum(gvn_num)\r\n# Print the\u00a0decagonal number of a given number.\r\nprint(\"The decagonal number of a given number {\", gvn_num, \"} = \")\r\nprint(rslt)\r\n<\/pre>\n
The decagonal number of a given number { 4 } = \r\n52<\/pre>\n
Method #2: Using Mathematical Formula (User Input)<\/span><\/h3>\n
\n
# Create a function say Find_DecagonalNum() which accepts the given number as an\r\n# argument and returns the decagonal number of the given number.\r\n\r\n\r\ndef Find_DecagonalNum(gvn_num):\r\n # Inside the function, calculate the decagonal number of a given number using the\r\n # above given mathematical formula and return it.\r\n return(4*gvn_num*gvn_num - 3*gvn_num)\r\n\r\n\r\n# Give the number as user input using the int(input()) function and store it in a variable.\r\ngvn_num = int(input(\"Enter some random number = \"))\r\n# Pass the given number to the Find_DecagonalNum() function store it in another\r\n# variable.\r\nrslt = Find_DecagonalNum(gvn_num)\r\n# Print the\u00a0decagonal number of a given number.\r\nprint(\"The decagonal number of a given number {\", gvn_num, \"} = \")\r\nprint(rslt)\r\n<\/pre>\n
Enter some random number = 10\r\nThe decagonal number of a given number { 10 } = \r\n370<\/pre>\n