# Check if a number is Triperfect Number

Here given code implementation process.

``````// C program
// Check if a number is Triperfect Number
#include <stdio.h>

//Check whether given number is Triperfect Number or not
void is_triperfect_no(int number)
{
if (number < 0)
{
return;
}
int n = 2;
//Add first and last factors
int sum = number + 1;
//Find other factors
while ((n * n) <= number)
{
if (number % n == 0)
{
if (number / n == n)
{
sum = sum + n;
}
else
{
sum = sum + n + (number / n);
}
}
n++;
}
if (number * 3 == sum)
{
printf("\n [%d] Is Triperfect Number", number);
}
else
{
printf("\n [%d] Is Not Triperfect Number", number);
}
}
int main()
{
//Test case
is_triperfect_no(120);
is_triperfect_no(567);
is_triperfect_no(672);
return 0;
}``````

#### Output

``````  Is Triperfect Number
 Is Not Triperfect Number
 Is Triperfect Number``````
``````/*
Java program
Check if a number is Triperfect Number
*/
class TriperfectNumber
{
//Check whether given number is Triperfect Number or not
public void is_triperfect_no(int number)
{
if (number < 0)
{
return;
}
int n = 2;
//Add first and last factors
int sum = number + 1;
//Find other factors
while ((n * n) <= number)
{
if (number % n == 0)
{
if (number / n == n)
{
sum = sum + n;
}
else
{
sum = sum + n + (number / n);
}
}
n++;
}
if (number * 3 == sum)
{
System.out.print("\n [" + number + "] Is Triperfect Number");
}
else
{
System.out.print("\n [" + number + "] Is Not Triperfect Number");
}
}
public static void main(String[] args)
{
TriperfectNumber obj = new TriperfectNumber();
//Test case
obj.is_triperfect_no(120);
obj.is_triperfect_no(567);
obj.is_triperfect_no(672);
}
}``````

#### Output

``````  Is Triperfect Number
 Is Not Triperfect Number
 Is Triperfect Number``````
``````//Include header file
#include <iostream>
using namespace std;

/*
C++ program
Check if a number is Triperfect Number
*/

class TriperfectNumber
{
public:
//Check whether given number is Triperfect Number or not
void is_triperfect_no(int number)
{
if (number < 0)
{
return;
}
int n = 2;
//Add first and last factors
int sum = number + 1;
//Find other factors
while ((n *n) <= number)
{
if (number % n == 0)
{
if (number / n == n)
{
sum = sum + n;
}
else
{
sum = sum + n + (number / n);
}
}
n++;
}
if (number *3 == sum)
{
cout << "\n [" << number << "] Is Triperfect Number";
}
else
{
cout << "\n [" << number << "] Is Not Triperfect Number";
}
}
};
int main()
{
TriperfectNumber obj = TriperfectNumber();
//Test case
obj.is_triperfect_no(120);
obj.is_triperfect_no(567);
obj.is_triperfect_no(672);
return 0;
}``````

#### Output

``````  Is Triperfect Number
 Is Not Triperfect Number
 Is Triperfect Number``````
``````//Include namespace system
using System;
/*
C# program
Check if a number is Triperfect Number
*/
class TriperfectNumber
{
//Check whether given number is Triperfect Number or not
public void is_triperfect_no(int number)
{
if (number < 0)
{
return;
}
int n = 2;
//Add first and last factors
int sum = number + 1;
//Find other factors
while ((n * n) <= number)
{
if (number % n == 0)
{
if (number / n == n)
{
sum = sum + n;
}
else
{
sum = sum + n + (number / n);
}
}
n++;
}
if (number * 3 == sum)
{
Console.Write("\n [" + number + "] Is Triperfect Number");
}
else
{
Console.Write("\n [" + number + "] Is Not Triperfect Number");
}
}
public static void Main(String[] args)
{
TriperfectNumber obj = new TriperfectNumber();
//Test case
obj.is_triperfect_no(120);
obj.is_triperfect_no(567);
obj.is_triperfect_no(672);
}
}``````

#### Output

``````  Is Triperfect Number
 Is Not Triperfect Number
 Is Triperfect Number``````
``````<?php

/*
Php program
Check if a number is Triperfect Number
*/

class TriperfectNumber
{
//Check whether given number is Triperfect Number or not
public	function is_triperfect_no(\$number)
{
if (\$number < 0)
{
return;
}
\$n = 2;
//Add first and last factors
\$sum = \$number + 1;
//Find other factors
while ((\$n * \$n) <= \$number)
{
if (\$number % \$n == 0)
{
if (intval(\$number / \$n) == \$n)
{
\$sum = \$sum + \$n;
}
else
{
\$sum = \$sum + \$n + (intval(\$number / \$n));
}
}
\$n++;
}
if (\$number * 3 == \$sum)
{
echo "\n [". \$number ."] Is Triperfect Number";
}
else
{
echo "\n [". \$number ."] Is Not Triperfect Number";
}
}
}

function main()
{
\$obj = new TriperfectNumber();
//Test case
\$obj->is_triperfect_no(120);
\$obj->is_triperfect_no(567);
\$obj->is_triperfect_no(672);
}
main();``````

#### Output

``````  Is Triperfect Number
 Is Not Triperfect Number
 Is Triperfect Number``````
``````/*
Node Js program
Check if a number is Triperfect Number
*/
class TriperfectNumber
{
//Check whether given number is Triperfect Number or not
is_triperfect_no(number)
{
if (number < 0)
{
return;
}
var n = 2;
//Add first and last factors
var sum = number + 1;
//Find other factors
while ((n * n) <= number)
{
if (number % n == 0)
{
if (parseInt(number / n) == n)
{
sum = sum + n;
}
else
{
sum = sum + n + (parseInt(number / n));
}
}
n++;
}
if (number * 3 == sum)
{
process.stdout.write("\n [" + number + "] Is Triperfect Number");
}
else
{
process.stdout.write("\n [" + number + "] Is Not Triperfect Number");
}
}
}

function main()
{
var obj = new TriperfectNumber();
//Test case
obj.is_triperfect_no(120);
obj.is_triperfect_no(567);
obj.is_triperfect_no(672);
}
main();``````

#### Output

``````  Is Triperfect Number
 Is Not Triperfect Number
 Is Triperfect Number``````
``````#   Python 3 program
#   Check if a number is Triperfect Number

class TriperfectNumber :
# Check whether given number is Triperfect Number or not
def is_triperfect_no(self, number) :
if (number < 0) :
return

n = 2
# Add first and last factors
sum = number + 1
# Find other factors
while ((n * n) <= number) :
if (number % n == 0) :
if (int(number / n) == n) :
sum = sum + n
else :
sum = sum + n + (int(number / n))

n += 1

if (number * 3 == sum) :
print("\n [", number ,"] Is Triperfect Number", end = "")
else :
print("\n [", number ,"] Is Not Triperfect Number", end = "")

def main() :
obj = TriperfectNumber()
# Test case
obj.is_triperfect_no(120)
obj.is_triperfect_no(567)
obj.is_triperfect_no(672)

if __name__ == "__main__": main()``````

#### Output

`````` [ 120 ] Is Triperfect Number
[ 567 ] Is Not Triperfect Number
[ 672 ] Is Triperfect Number``````
``````#   Ruby program
#   Check if a number is Triperfect Number

class TriperfectNumber
# Check whether given number is Triperfect Number or not
def is_triperfect_no(number)
if (number < 0)
return
end

n = 2
# Add first and last factors
sum = number + 1
# Find other factors
while ((n * n) <= number)
if (number % n == 0)
if (number / n == n)
sum = sum + n
else
sum = sum + n + (number / n)
end

end

n += 1
end

if (number * 3 == sum)
print("\n [", number ,"] Is Triperfect Number")
else
print("\n [", number ,"] Is Not Triperfect Number")
end

end

end

def main()
obj = TriperfectNumber.new()
# Test case
obj.is_triperfect_no(120)
obj.is_triperfect_no(567)
obj.is_triperfect_no(672)
end

main()``````

#### Output

``````  Is Triperfect Number
 Is Not Triperfect Number
 Is Triperfect Number``````
``````/*
Scala program
Check if a number is Triperfect Number
*/
class TriperfectNumber
{
//Check whether given number is Triperfect Number or not
def is_triperfect_no(number: Int): Unit = {
if (number < 0)
{
return;
}
var n: Int = 2;
//Add first and last factors
var sum: Int = number + 1;
//Find other factors
while ((n * n) <= number)
{
if (number % n == 0)
{
if ((number / n).toInt == n)
{
sum = sum + n;
}
else
{
sum = sum + n + ((number / n).toInt);
}
}
n += 1;
}
if (number * 3 == sum)
{
print("\n [" + number + "] Is Triperfect Number");
}
else
{
print("\n [" + number + "] Is Not Triperfect Number");
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: TriperfectNumber = new TriperfectNumber();
//Test case
obj.is_triperfect_no(120);
obj.is_triperfect_no(567);
obj.is_triperfect_no(672);
}
}``````

#### Output

``````  Is Triperfect Number
 Is Not Triperfect Number
 Is Triperfect Number``````
``````/*
Swift 4 program
Check if a number is Triperfect Number
*/
class TriperfectNumber
{
//Check whether given number is Triperfect Number or not
func is_triperfect_no(_ number: Int)
{
if (number < 0)
{
return;
}
var n: Int = 2;
//Add first and last factors
var sum: Int = number + 1;
//Find other factors
while ((n * n) <= number)
{
if (number % n == 0)
{
if (number / n == n)
{
sum = sum + n;
}
else
{
sum = sum + n + (number / n);
}
}
n += 1;
}
if (number * 3 == sum)
{
print("\n [", number ,"] Is Triperfect Number", terminator: "");
}
else
{
print("\n [", number ,"] Is Not Triperfect Number", terminator: "");
}
}
}
func main()
{
let obj: TriperfectNumber = TriperfectNumber();
//Test case
obj.is_triperfect_no(120);
obj.is_triperfect_no(567);
obj.is_triperfect_no(672);
}
main();``````

#### Output

`````` [ 120 ] Is Triperfect Number
[ 567 ] Is Not Triperfect Number
[ 672 ] Is Triperfect Number``````

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.