Centered triangular number in PL/SQL Last Updated : 31 Oct, 2018 Comments Improve Suggest changes Like Article Like Report Prerequisite - PL/SQL introduction In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Given n and task is to find nth centered triangular number. A centered triangular number is a centered number that represents a triangle with a dot in the center and all other dots surrounding the center in successive triangular layers. Examples: Input: n = 6 Output: 64 Input: n = 10 Output: 166 The first few centered triangular number series are: 1, 4, 10, 19, 31, 46, 64, 85, 109, 136, 166, 199, 235, 274, 316, 361, 409, 460……………………… Approach nth Term of centered triangular number is given by: CT_{n}=(3n^2+3n+2)/2 Below is the required implementation: SQL --PL/SQL Program to find the nth Centered triangular number -- declaration section DECLARE x NUMBER; n NUMBER; --utility function FUNCTION Centered_triangular_num(n IN NUMBER) RETURN NUMBER IS z NUMBER; BEGIN --formula applying z := (3 * n * n + 3 * n + 2) / 2; RETURN z; END; --driver code BEGIN n := 3; x := centered_triangular_num(n); dbms_output.Put_line(x); n := 12; x := centered_trigunal_num(n); dbms_output.Put_line(x); END; --End of program Output: 19 235 References: https://en.wikipedia.org/wiki/Centered_triangular_number Comment More infoAdvertise with us Next Article Centered triangular number in PL/SQL V vt_m Follow Improve Article Tags : Misc SQL SQL-PL/SQL triangular-number Practice Tags : Misc Similar Reads GCD of two numbers in PL/SQL Prerequisite - PL/SQL introduction In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Given two numbers and task is to find the GCD (Greatest 1 min read Sum and average of three numbers in PL/SQL Prerequisite - PL/SQL introduction In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Given three numbers and the task is to find out the sum 2 min read Convert the given numbers into words in Pl/SQL Prerequisite - PL/SQL introduction In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Given a number and task is to convert each digit of the 2 min read Find the factorial of a number in pl/sql Given a number, your task to print the factorial of that number using pl/sql. Examples: Input : 5 Output : 120 Explanation: 5! = 5 * 4 * 3 * 2 * 1 = 120 Input : 4 Output : 24 Basic structure of pl/sql block declare -- declare all the variables begin -- for start block -- make a program here end -- f 1 min read Floyd's triangle in PL/SQL Prerequisite - PL/SQL introduction In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Floyd's triangle is a right-angled triangular array of 2 min read Factorial of a number in PL/SQL Prerequisite - PL/SQL introduction In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Here, first, we take three variables num, fact, and tem 1 min read Check Armstrong Number in PL/SQL Given a number x, determine whether the given number is Armstrong number or not. A positive integer of n digits is called an Armstrong number of order n (order is number of digits) if. abcd... = pow(a, n) + pow(b, n) + pow(c, n) + pow(d, n) + .... Example: Input : 153 Output : Yes 153 is an Armstron 1 min read Swap two numbers in PL/SQL In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Basic structure of pl/sql block declare -- declare all the variables begin -- for start bl 1 min read Find the area and perimeter of right triangle in PL/SQL Prerequisite - PL/SQL introduction In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Given the lengths of hypotenuse, base, and height of a 2 min read Sum of digits of a number in PL/ SQL Prerequisite - PL/SQL introduction In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Given a number and task is to find the sum of digits of 1 min read Like