A Number is a Trimorphic number if the cube of the number ends in the number itself.
Example:
Given Number=5
5⇒5³=125(ends with the number itself)
so, 5 is Trimorphic Number.
Given Number=10
10⇒10³=1000(ends with not number itself)
so, 10 is not a Trimorphic Number.
Problem statement:- Program to check whether the number is Trimorphic Number or Not.
Data requirement:-
Input Data:- num
Output Data:- String output
Additional Data:- num, flag, cube_power
Program in C
Example:
Given Number=5
5⇒5³=125(ends with the number itself)
so, 5 is Trimorphic Number.
Given Number=10
10⇒10³=1000(ends with not number itself)
so, 10 is not a Trimorphic Number.
Problem statement:- Program to check whether the number is Trimorphic Number or Not.
Data requirement:-
Input Data:- num
Output Data:- String output
Additional Data:- num, flag, cube_power
Program in C
Here is the source code of the C Program to check whether the number is Trimorphic Number or Not.
Code:
//Trimorphic Number Or Not
#include<stdio.h>
int main()
{
int num;
printf("Enter the number:");
scanf("%d",&num);
int flag=0;
int cube_power=num*num*num;
while(num!=0)
{
if(num%10!=cube_power%10)
{
flag=1;
break;
}
num/=10;
cube_power/=10;
}
if(flag==0)
printf("It is a Trimorphic Number.");
else
printf("It is not a Trimorphic Number.");
}
#include<stdio.h>
int main()
{
int num;
printf("Enter the number:");
scanf("%d",&num);
int flag=0;
int cube_power=num*num*num;
while(num!=0)
{
if(num%10!=cube_power%10)
{
flag=1;
break;
}
num/=10;
cube_power/=10;
}
if(flag==0)
printf("It is a Trimorphic Number.");
else
printf("It is not a Trimorphic Number.");
}
Input/Output:
Enter the number:5
It is a Trimorphic Number.
Program in C++
Here is the source code of the C++ Program to check whether the number is Trimorphic Number or Not.
It is a Trimorphic Number.
Program in C++
Here is the source code of the C++ Program to check whether the number is Trimorphic Number or Not.
Code:
#include <iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter the number:";
cin>>num;
int flag=0;
int cube_power=num*num*num;
while(num!=0)
{
if(num%10!=cube_power%10)
{
flag=1;
break;
}
num/=10;
cube_power/=10;
}
if(flag==0)
cout<<"It is a Trimorphic Number.";
else
cout<<"It is not a Trimorphic Number.";
}
Input/Output:using namespace std;
int main()
{
int num;
cout<<"Enter the number:";
cin>>num;
int flag=0;
int cube_power=num*num*num;
while(num!=0)
{
if(num%10!=cube_power%10)
{
flag=1;
break;
}
num/=10;
cube_power/=10;
}
if(flag==0)
cout<<"It is a Trimorphic Number.";
else
cout<<"It is not a Trimorphic Number.";
}
Enter the number:10
It is not a Trimorphic Number.
Program in Java
It is not a Trimorphic Number.
Program in Java
Here is the source code of the Java Program to check whether the number is Trimorphic Number or Not.
Code:
import java.util.Scanner;
public class TrimorphicNumberOrNot {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num;
System.out.println("Enter a number:");
num=cs.nextInt();
int flag=0;
int cube_power=num*num*num;
while(num!=0)
{
if(num%10!=cube_power%10)
{
flag=1;
break;
}
num/=10;
cube_power/=10;
}
if(flag==0)
System.out.println("It is a Trimorphic Number.");
else
System.out.println("It is not a Trimorphic Number.");
cs.close();
}
}
public class TrimorphicNumberOrNot {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num;
System.out.println("Enter a number:");
num=cs.nextInt();
int flag=0;
int cube_power=num*num*num;
while(num!=0)
{
if(num%10!=cube_power%10)
{
flag=1;
break;
}
num/=10;
cube_power/=10;
}
if(flag==0)
System.out.println("It is a Trimorphic Number.");
else
System.out.println("It is not a Trimorphic Number.");
cs.close();
}
}
Input/Output:
Enter a number:
6
It is a Trimorphic Number.
6
It is a Trimorphic Number.
Program in Python
Here is the source code of the Program to check whether the number is a Trimorphic Number or Not.
Code:
num=int(input("Enter a number:"))
flag=0
cube_power=num*num*num
while num!=0:
if num%10!=cube_power%10:
flag=1
break
num//=10
cube_power//=10
if flag==0:
print("It is a Trimorphic Number.")
else:
print("It is Not a Trimorphic Number.")
flag=0
cube_power=num*num*num
while num!=0:
if num%10!=cube_power%10:
flag=1
break
num//=10
cube_power//=10
if flag==0:
print("It is a Trimorphic Number.")
else:
print("It is Not a Trimorphic Number.")
Input/Output:
Enter a number:15
It is Not a Trimorphic Number.
It is Not a Trimorphic Number.
0 Comments
Please do not Enter any spam link in the comment box