-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTrimorphic Number.cpp
More file actions
73 lines (60 loc) · 1.36 KB
/
Trimorphic Number.cpp
File metadata and controls
73 lines (60 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
This program check if the user input is a Trimorphic number or not.
Also print the Trimorphic Number Upto Given Input number.
A Trimorphic number is a number whose cube ends in the number itself.
For example:
Input: 4
Output: true (4^3 is 64, which ends in 4)
Input: 24
Output: true (24^3 = 13824)
Input: 249
Output: true (249^3 = 15438249)
*/
#include <iostream>
#include <cmath>
using namespace std;
int Trimorphic_Check(int num)
{
int i,cube,n,nd,ln;
cube=pow(num,3);
n=num;
nd=0;
while(n!=0){
nd++;
n=n/10;
}
n=cube; ln=0;
for(i=1;i<=nd;i++){
ln=ln*10+n%10;
n=n/10;
}
n=ln; ln=0;
while(n!=0){
ln=ln*10+n%10;
n=n/10;
}
if(num==ln)
return 1;
else
return 0;
}
int main()
{
int num;
// cout<<"Enter a Number : ";
cin>>num;
cout<<"Entered Number : "<<num<<endl<<endl;
if(Trimorphic_Check(num)){
cout<<"👍 "<<num<<" is a Trimorphic Number.";
cout<<"\n\t-> ("<<num<<"^3 is "<<(int)pow(num,3)<<", which ends in "<<num<<")";
}
else{
cout<<"❌ "<<num<<" is Not a Trimorphic Number.";
cout<<"\n\t-> ("<<num<<"^3 is "<<(int)pow(num,3)<<", which Not ends with "<<num<<")";
}
cout<<"\n\nTrimorphic Numbers Upto "<<num<<" Are :"<<endl<<endl;
for(int i=1;i<=num;i++)
if(Trimorphic_Check(i))
cout<<i<<", ";
return 0;
}