Program for Centered Icosahedral Number in C++

C++Server Side ProgrammingProgramming

Given with a value ‘n’ and the task is to generate the centered Icosahedral number for n and centered Icosahedral series till n and display the results.

What is centered Icosahedral number?

Centered Icosahedral number is a centered number used for representing an icosahedrons(it is a polyhedron figure with 20 faces).

The first few centered icosahedral number series till n = 1000 are −

1, 13, 55, 147, 309, 561, 923

Centered Icosahedral number can be calculated using the formula −

$$(2n+1)\times\frac{5n^{2}+5n+3}{3}$$

Input 

number: 20

Output 

Centered Icosahedral Number is : 28741

Input 

number: 12

Output 

Centered Icosahedral Number is : 6525

Algorithm

Start
Step 1→ declare function to calculate centered iscosahedral number
   int calculate(int num)
      return (2 * num + 1) * (5 * num * num + 5 * num + 3) / 3
Step 2→ In main()
   Declare int num = 20
   Print calculate(num)
Stop

Example

 Live Demo

#include <bits/stdc++.h>
using namespace std;
//calculate Centered Icosahedral Number
int calculate(int num){
   return (2 * num + 1) * (5 * num * num + 5 * num + 3) / 3;
}
int main(){
   int num = 20;
   cout<<"Centered Icosahedral Number is : "<<calculate(num) << endl;
   return 0;
}

Output

If run the above code it will generate the following output −

Centered Icosahedral Number is : 28741
raja
Updated on 13-Aug-2020 07:42:50

Advertisements