-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighlow.cpp
70 lines (58 loc) · 1.29 KB
/
highlow.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
#include<iostream>
using namespace std;
bool HighLow(int n);
int main()
{
int num;
cout << "\nEnter a number: ";
cin >> num;
if(HighLow(num))
cout << "\nTrue";
else
cout << "\nFalse";
return 0;
}
bool HighLow(int n)
{
int rem, iter = 0, high = 0, low = 0, high1 = 0, low1 = 0;
while (n > 0)
{
rem = n % 10;
cout << endl << rem;
n /= 10;
if(iter % 2 == 0)
{
cout << " &";
if ((rem > 4) && (rem < 10))
{
high++;
if (!((low == 0) || (high1 == 0)))
return false;
}
else if ((rem >= 0) && (rem < 5))
{
low++;
if (!((high == 0) || (low1 == 0)))
return false;
}
}
else
{
cout << " *";
if ((rem > 4) && (rem < 10))
{
high1++;
if ((low1 == 0) || (high == 0))
return false;
}
else if ((rem >= 0) && (rem < 5))
{
low1++;
if (!((high1 == 0) || (low == 0)))
return false;
}
}
iter++;
}
return true;
}