-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPointersExamples_5.cpp
49 lines (44 loc) · 1011 Bytes
/
PointersExamples_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
#include<iostream>
using namespace std;
int lengthOfDigits(int *);
int reverseOfDigits(int* );
int main()
{
int range;
cout<<"Enter a number: ";
cin>>range;
int len ;
int rev ;
for(int i =1; i<=range; i++)
{
int temp = i;
int temp2 = i;
int *ptr = &temp; // ptr is a pointer variable that holds the address of temp.
rev = reverseOfDigits(ptr); // rev is a variable that holds the reverse of the number.
if(temp2 == rev){
cout<< i << "\n";
}
}
}
int lengthOfDigits(int *number)
{
int count=0;
while(*number>0)
{
*number=*number/10;
count++;
}
return count;
}
int reverseOfDigits(int *num){
int temp = *num;
int len = lengthOfDigits(num);
int digit, sum = 0;
for(int i=1; i<=len ; i++)
{
digit = temp%10;
*&sum = *&sum * 10 + digit;
temp=temp/10;
}
return *∑
}