-
Notifications
You must be signed in to change notification settings - Fork 2
/
PointerToPointers_5.cpp
51 lines (47 loc) · 1.07 KB
/
PointerToPointers_5.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
#include<iostream>
using namespace std;
int lengthOfDigits(int **);
int reverse(int **);
int main()
{
int num , temp, temp1;
int *ptr;
cout << "Enter the number :" << endl;
cin >> num;
temp = num;
ptr = #
int rev = reverse(&ptr);
cout << "Reverse of " << temp << " is: " << rev << endl;
if(temp == rev){
cout << "The number " <<temp <<" is palindrome" << endl;
}
else{
cout << "The number " <<temp <<" is not palindrome" << endl;
}
return 0;
}
int lengthOfDigits(int **number)
{
int count=0;
int *ptr_new = &count ;
int **ptriptr = &ptr_new ;
while(**number>0)
{
**number=**number/10;
**ptriptr = **ptriptr + 1;
}
return **ptriptr;
}
int reverse(int **ptrptr)
{
int temp = **ptrptr;
int digit,sum = 0;
int len = lengthOfDigits(ptrptr); //Now ptrptr becomes zero 0.
for(int i=1; i<=len ; i++)
{
digit = temp%10;
sum = sum * 10 + digit;
temp=temp/10;
}
return sum;
}