This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: abhi6691 on Aug 8th, 2011  |  syntax: None  |  size: 0.94 KB  |  views: 76  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include<iostream>
  2. #include<math.h>
  3. #include<stdlib.h>
  4. using namespace std;
  5.  
  6. int reverse(int num)
  7. {
  8.    int rev_num=0;
  9.    while(num>0)
  10.    {
  11.       rev_num= rev_num*10 + num%10;
  12.       num= num/10;
  13.    }
  14.    return rev_num;
  15. }
  16.  
  17. bool isPrime(int num)
  18. {
  19.    int flag=1;
  20.    if(num%2==0)
  21.    {
  22.       return false;
  23.    }
  24.    else
  25.    {
  26.       int limit= (int)(sqrt(num));
  27.       int denom= 3;
  28.       while(denom<=limit)
  29.       {
  30.          if(num%denom==0)
  31.          {
  32.             flag=0;
  33.             return false;
  34.          }
  35.          else denom+=2;
  36.       }
  37.       return true;
  38.    }
  39. }
  40.  
  41.  
  42.  
  43. int main()
  44. {
  45.    int num;
  46.    cin>>num;
  47.    
  48.    int flag=0;
  49.    while(flag==0)
  50.    {
  51.       int rev_num = reverse(num);
  52.       if(num-rev_num ==0)
  53.       {
  54.          bool ans = isPrime(num);
  55.          if(ans== true)
  56.             {
  57.                 cout<<num;
  58.                 flag=1;
  59.             }
  60.          else num++;
  61.       }
  62.       else num++;
  63.    }
  64. }
clone this paste RAW Paste Data