Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- void pal(int a, int &b)
- {
- int c1=0,c2=0,p1,p2;
- b=0;
- for(int i=a; i>=a; i++)
- {
- int x=i;
- while(x)
- {
- b=b*10+x%10;
- x=x/10;
- }
- // c1++;
- if (x==i)
- {
- p1=x;
- i=a-1;
- }
- }
- for(int i=a; i>0; i--)
- {
- int x=i;
- while(x)
- {
- b=b*10+x%10;
- x=x/10;
- }
- // c2++;
- if (x==i)
- {
- p2=x;
- i=-1;
- }
- }
- if(p1>p2)
- b=p1;
- else
- b=p2;
- }
- int main()
- {
- int a=126, b;
- pal(a,b);
- cout<<b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement