Tech Number Program
Here given code implementation process.
// C program
// Tech Number Program
#include <stdio.h>
#include <math.h>
// Determine that given number is tech number or not
void isTechNo(int number)
{
// Define some auxiliary variable
int length = 0;
int temp = number;
int lhs = 0;
int rhs = 0;
int result = 0;
// Count the length of number of digits
while (temp != 0)
{
temp = temp / 10;
length++;
}
if ((length % 2) == 0)
{
// Get first half part
lhs = number / ((int) pow(10, length / 2));
// Get second half part
rhs = number % ((int) pow(10, length / 2));
if (((lhs + rhs) * (lhs + rhs)) == number)
{
result = 1;
}
}
if (result == 1)
{
// When number is tech number
printf(" %d is tech number \n", number);
}
else
{
printf(" %d is not tech number \n", number);
}
}
int main()
{
// Test Case
// number 81
// 8+1 = 9
// 9*9 = 81
// Output : Yes
isTechNo(81);
// number 3025
// 30 + 25 = 55
// 55*55 = 3025
// Output : Yes
isTechNo(3025);
// number 91
// 9 + 1 = 10
// 10*10 = 100
// Output : No
isTechNo(91);
// number 9801
// 98 + 1 = 99
// 99*99 = 9801
// Output : Yes
isTechNo(9801);
return 0;
}
input
81 is tech number
3025 is tech number
91 is not tech number
9801 is tech number
/*
Java Program for
Tech Number
*/
class TechNo
{
// Determine that given number is tech number or not
public void isTechNo(int number)
{
// Define some auxiliary variable
int length = 0;
int temp = number;
int lhs = 0;
int rhs = 0;
int result = 0;
// Count the length of number of digits
while (temp != 0)
{
temp = temp / 10;
length++;
}
if ((length % 2) == 0)
{
// Get first half part
lhs = number / ((int) Math.pow(10, length / 2));
// Get second half part
rhs = number % ((int) Math.pow(10, length / 2));
if (((lhs + rhs) * (lhs + rhs)) == number)
{
result = 1;
}
}
if (result == 1)
{
// When number is tech number
System.out.println(" " + number + " is tech number");
}
else
{
System.out.println(" " + number + " is not tech number");
}
}
public static void main(String[] args)
{
TechNo task = new TechNo();
// Test Case
// number 81
// 8+1 = 9
// 9*9 = 81
// Output : Yes
task.isTechNo(81);
// number 3025
// 30 + 25 = 55
// 55*55 = 3025
// Output : Yes
task.isTechNo(3025);
// number 91
// 9 + 1 = 10
// 10*10 = 100
// Output : No
task.isTechNo(91);
// number 9801
// 98 + 1 = 99
// 99*99 = 9801
// Output : Yes
task.isTechNo(9801);
}
}
input
81 is tech number
3025 is tech number
91 is not tech number
9801 is tech number
// Include header file
#include <iostream>
#include <math.h>
using namespace std;
/*
C++ Program for
Tech Number
*/
class TechNo
{
public:
// Determine that given number is tech number or not
void isTechNo(int number)
{
// Define some auxiliary variable
int length = 0;
int temp = number;
int lhs = 0;
int rhs = 0;
int result = 0;
// Count the length of number of digits
while (temp != 0)
{
temp = temp / 10;
length++;
}
if ((length % 2) == 0)
{
// Get first half part
lhs = number / ((int) pow(10, length / 2));
// Get second half part
rhs = number % ((int) pow(10, length / 2));
if (((lhs + rhs) *(lhs + rhs)) == number)
{
result = 1;
}
}
if (result == 1)
{
// When number is tech number
cout << " " << number << " is tech number" << endl;
}
else
{
cout << " " << number << " is not tech number" << endl;
}
}
};
int main()
{
TechNo *task = new TechNo();
// Test Case
// number 81
// 8+1 = 9
// 9*9 = 81
// Output : Yes
task->isTechNo(81);
// number 3025
// 30 + 25 = 55
// 55*55 = 3025
// Output : Yes
task->isTechNo(3025);
// number 91
// 9 + 1 = 10
// 10*10 = 100
// Output : No
task->isTechNo(91);
// number 9801
// 98 + 1 = 99
// 99*99 = 9801
// Output : Yes
task->isTechNo(9801);
return 0;
}
input
81 is tech number
3025 is tech number
91 is not tech number
9801 is tech number
// Include namespace system
using System;
/*
Csharp Program for
Tech Number
*/
public class TechNo
{
// Determine that given number is tech number or not
public void isTechNo(int number)
{
// Define some auxiliary variable
int length = 0;
int temp = number;
int lhs = 0;
int rhs = 0;
int result = 0;
// Count the length of number of digits
while (temp != 0)
{
temp = temp / 10;
length++;
}
if ((length % 2) == 0)
{
// Get first half part
lhs = number / ((int) Math.Pow(10, length / 2));
// Get second half part
rhs = number % ((int) Math.Pow(10, length / 2));
if (((lhs + rhs) * (lhs + rhs)) == number)
{
result = 1;
}
}
if (result == 1)
{
// When number is tech number
Console.WriteLine(" " + number + " is tech number");
}
else
{
Console.WriteLine(" " + number + " is not tech number");
}
}
public static void Main(String[] args)
{
TechNo task = new TechNo();
// Test Case
// number 81
// 8+1 = 9
// 9*9 = 81
// Output : Yes
task.isTechNo(81);
// number 3025
// 30 + 25 = 55
// 55*55 = 3025
// Output : Yes
task.isTechNo(3025);
// number 91
// 9 + 1 = 10
// 10*10 = 100
// Output : No
task.isTechNo(91);
// number 9801
// 98 + 1 = 99
// 99*99 = 9801
// Output : Yes
task.isTechNo(9801);
}
}
input
81 is tech number
3025 is tech number
91 is not tech number
9801 is tech number
<?php
/*
Php Program for
Tech Number
*/
class TechNo
{
// Determine that given number is tech number or not
public function isTechNo($number)
{
// Define some auxiliary variable
$length = 0;
$temp = $number;
$lhs = 0;
$rhs = 0;
$result = 0;
// Count the length of number of digits
while ($temp != 0)
{
$temp = (int)($temp / 10);
$length++;
}
if (($length % 2) == 0)
{
// Get first half part
$lhs = (int)($number / ((int) pow(10, (int)($length / 2))));
// Get second half part
$rhs = $number % ((int) pow(10, (int)($length / 2)));
if ((($lhs + $rhs) * ($lhs + $rhs)) == $number)
{
$result = 1;
}
}
if ($result == 1)
{
// When number is tech number
echo " ".$number.
" is tech number".
"\n";
}
else
{
echo " ".$number.
" is not tech number".
"\n";
}
}
}
function main()
{
$task = new TechNo();
// Test Case
// number 81
// 8+1 = 9
// 9*9 = 81
// Output : Yes
$task->isTechNo(81);
// number 3025
// 30 + 25 = 55
// 55*55 = 3025
// Output : Yes
$task->isTechNo(3025);
// number 91
// 9 + 1 = 10
// 10*10 = 100
// Output : No
$task->isTechNo(91);
// number 9801
// 98 + 1 = 99
// 99*99 = 9801
// Output : Yes
$task->isTechNo(9801);
}
main();
input
81 is tech number
3025 is tech number
91 is not tech number
9801 is tech number
/*
Node JS Program for
Tech Number
*/
class TechNo
{
// Determine that given number is tech number or not
isTechNo(number)
{
// Define some auxiliary variable
var length = 0;
var temp = number;
var lhs = 0;
var rhs = 0;
var result = 0;
// Count the length of number of digits
while (temp != 0)
{
temp = parseInt(temp / 10);
length++;
}
if ((length % 2) == 0)
{
// Get first half part
lhs = parseInt(number / ((int) Math.pow(10, parseInt(length / 2))));
// Get second half part
rhs = number % ((int) Math.pow(10, parseInt(length / 2)));
if (((lhs + rhs) * (lhs + rhs)) == number)
{
result = 1;
}
}
if (result == 1)
{
// When number is tech number
console.log(" " + number + " is tech number");
}
else
{
console.log(" " + number + " is not tech number");
}
}
}
function main()
{
var task = new TechNo();
// Test Case
// number 81
// 8+1 = 9
// 9*9 = 81
// Output : Yes
task.isTechNo(81);
// number 3025
// 30 + 25 = 55
// 55*55 = 3025
// Output : Yes
task.isTechNo(3025);
// number 91
// 9 + 1 = 10
// 10*10 = 100
// Output : No
task.isTechNo(91);
// number 9801
// 98 + 1 = 99
// 99*99 = 9801
// Output : Yes
task.isTechNo(9801);
}
main();
input
81 is tech number
3025 is tech number
91 is not tech number
9801 is tech number
import math
# Python 3 Program for
# Tech Number
class TechNo :
# Determine that given number is tech number or not
def isTechNo(self, number) :
length = 0
temp = number
lhs = 0
rhs = 0
result = 0
# Count the length of number of digits
while (temp != 0) :
temp = int(temp / 10)
length += 1
if ((length % 2) == 0) :
# Get first half part
lhs = int(number / ((10 ** int(length / 2))))
# Get second half part
rhs = number % ((10 ** int(length / 2)))
if (((lhs + rhs) * (lhs + rhs)) == number) :
result = 1
if (result == 1) :
# When number is tech number
print(" ", number ," is tech number")
else :
print(" ", number ," is not tech number")
def main() :
task = TechNo()
# Test Case
# number 81
# 8+1 = 9
# 9*9 = 81
# Output : Yes
task.isTechNo(81)
# number 3025
# 30 + 25 = 55
# 55*55 = 3025
# Output : Yes
task.isTechNo(3025)
# number 91
# 9 + 1 = 10
# 10*10 = 100
# Output : No
task.isTechNo(91)
# number 9801
# 98 + 1 = 99
# 99*99 = 9801
# Output : Yes
task.isTechNo(9801)
if __name__ == "__main__": main()
input
81 is tech number
3025 is tech number
91 is not tech number
9801 is tech number
# Ruby Program for
# Tech Number
class TechNo
# Determine that given number is tech number or not
def isTechNo(number)
# Define some auxiliary variable
length = 0
temp = number
lhs = 0
rhs = 0
result = 0
# Count the length of number of digits
while (temp != 0)
temp = temp / 10
length += 1
end
if ((length % 2) == 0)
# Get first half part
lhs = number / ( 10 ** (length / 2))
# Get second half part
rhs = number % ( 10 ** (length / 2))
if (((lhs + rhs) * (lhs + rhs)) == number)
result = 1
end
end
if (result == 1)
# When number is tech number
print(" ", number ," is tech number", "\n")
else
print(" ", number ," is not tech number", "\n")
end
end
end
def main()
task = TechNo.new()
# Test Case
# number 81
# 8+1 = 9
# 9*9 = 81
# Output : Yes
task.isTechNo(81)
# number 3025
# 30 + 25 = 55
# 55*55 = 3025
# Output : Yes
task.isTechNo(3025)
# number 91
# 9 + 1 = 10
# 10*10 = 100
# Output : No
task.isTechNo(91)
# number 9801
# 98 + 1 = 99
# 99*99 = 9801
# Output : Yes
task.isTechNo(9801)
end
main()
input
81 is tech number
3025 is tech number
91 is not tech number
9801 is tech number
/*
Scala Program for
Tech Number
*/
class TechNo()
{
// Determine that given number is tech number or not
def isTechNo(number: Int): Unit = {
// Define some auxiliary variable
var length: Int = 0;
var temp: Int = number;
var lhs: Int = 0;
var rhs: Int = 0;
var result: Int = 0;
// Count the length of number of digits
while (temp != 0)
{
temp = (temp / 10).toInt;
length += 1;
}
if ((length % 2) == 0)
{
// Get first half part
lhs = (number / ( Math.pow(10, (length / 2).toInt))).toInt;
// Get second half part
rhs = number % ( Math.pow(10, (length / 2).toInt)).toInt;
if (((lhs + rhs) * (lhs + rhs)) == number)
{
result = 1;
}
}
if (result == 1)
{
// When number is tech number
println(" " + number + " is tech number");
}
else
{
println(" " + number + " is not tech number");
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: TechNo = new TechNo();
// Test Case
// number 81
// 8+1 = 9
// 9*9 = 81
// Output : Yes
task.isTechNo(81);
// number 3025
// 30 + 25 = 55
// 55*55 = 3025
// Output : Yes
task.isTechNo(3025);
// number 91
// 9 + 1 = 10
// 10*10 = 100
// Output : No
task.isTechNo(91);
// number 9801
// 98 + 1 = 99
// 99*99 = 9801
// Output : Yes
task.isTechNo(9801);
}
}
input
81 is tech number
3025 is tech number
91 is not tech number
9801 is tech number
import Foundation;
/*
Swift 4 Program for
Tech Number
*/
class TechNo
{
// Determine that given number is tech number or not
func isTechNo(_ number: Int)
{
// Define some auxiliary variable
var length: Int = 0;
var temp: Int = number;
var lhs: Int = 0;
var rhs: Int = 0;
var result: Int = 0;
// Count the length of number of digits
while (temp != 0)
{
temp = temp / 10;
length += 1;
}
if ((length % 2) == 0)
{
// Get first half part
lhs = number / (Int(pow(10.0, Double(length / 2))));
// Get second half part
rhs = number % (Int(pow(10.0, Double(length / 2))));
if (((lhs + rhs) * (lhs + rhs)) == number)
{
result = 1;
}
}
if (result == 1)
{
// When number is tech number
print(" ", number, " is tech number");
}
else
{
print(" ", number, " is not tech number");
}
}
}
func main()
{
let task: TechNo = TechNo();
// Test Case
// number 81
// 8+1 = 9
// 9*9 = 81
// Output : Yes
task.isTechNo(81);
// number 3025
// 30 + 25 = 55
// 55*55 = 3025
// Output : Yes
task.isTechNo(3025);
// number 91
// 9 + 1 = 10
// 10*10 = 100
// Output : No
task.isTechNo(91);
// number 9801
// 98 + 1 = 99
// 99*99 = 9801
// Output : Yes
task.isTechNo(9801);
}
main();
input
81 is tech number
3025 is tech number
91 is not tech number
9801 is tech number
/*
Kotlin Program for
Tech Number
*/
class TechNo
{
// Determine that given number is tech number or not
fun isTechNo(number: Int): Unit
{
// Define some auxiliary variable
var length: Int = 0;
var temp: Int = number;
var lhs: Int ;
var rhs: Int ;
var result: Int = 0;
while (temp != 0)
{
temp = temp / 10;
length += 1;
}
if ((length % 2) == 0)
{
// Get first half part
lhs = number / (Math.pow(10.0, (length / 2).toDouble())).toInt();
// Get second half part
rhs = number % (Math.pow(10.0, (length / 2).toDouble())).toInt();
if (((lhs + rhs) * (lhs + rhs)) == number)
{
result = 1;
}
}
if (result == 1)
{
// When number is tech number
println(" " + number + " is tech number");
}
else
{
println(" " + number + " is not tech number");
}
}
}
fun main(args: Array < String > ): Unit
{
val task: TechNo = TechNo();
// Test Case
// number 81
// 8+1 = 9
// 9*9 = 81
// Output : Yes
task.isTechNo(81);
// number 3025
// 30 + 25 = 55
// 55*55 = 3025
// Output : Yes
task.isTechNo(3025);
// number 91
// 9 + 1 = 10
// 10*10 = 100
// Output : No
task.isTechNo(91);
// number 9801
// 98 + 1 = 99
// 99*99 = 9801
// Output : Yes
task.isTechNo(9801);
}
input
81 is tech number
3025 is tech number
91 is not tech number
9801 is tech number
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.
New Comment