-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitchCase.cpp
112 lines (93 loc) · 1.54 KB
/
SwitchCase.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include<iostream>
using namespace std;
void Palindrome();
bool PrimeNumber();
void Armstrong();
int main()
{
int sel;
cout<<"select the operation"<<endl;
cout<<"1.Palindrome \n 2.PrimeNumber \n 3.armstrong number "<<endl;
cin>>sel;
switch (sel)
{
case 1:
Palindrome();
break;
case 2:
PrimeNumber();
break;
case 3:
Armstrong();
break;
default:
break;
}
}
void Palindrome()
{
int num,org=0,rev=0,rem;
cout<<"Enter the number"<<endl;
cin>>num;
for(org=num;num!=0;)
{
rem=num%10;
rem=(rem*10)+rem;
num=num/10;
}
if(org==rev)
{
cout<<"Palindrome"<<endl;
}
else
{
cout<<"Not a palindrome!!"<<endl;
}
}
bool PrimeNumber()
{
int num;
cout<<"Enter the number ="<<endl;
cin>>num;
bool check=true;
if(num==0 || num==1)
{
return false;
}
for(int i=2;i<num;i++)
{
if(num%i==0)
{
return false ;
break;
}
}
if(check)
{
cout<<"Prime NUmber "<<endl;
}
else
{
cout<<"NOt a prime number"<<endl;
}
}
void Armstrong()
{
int num,sum,rem,i;
cout<<"Enter the number range till"<<endl;
cin>>num;
for( i =0;i<num;i++)
{
sum=0;
while(num>0)
{
rem=num%10;
sum=sum+rem*rem*rem;
num=num/10;
}
}
if(sum==i)
{
cout<<i<<endl;
}
}