My Professional Profile

I am Johnson Augustine Sr.Software Engineer and System Architect. I have 10 Yrs of hands on expertise in ASP.net MVC 5 , Angular 5 , C# MVC Razor, WPF MVVM , Android , IOS Swift 3 , IOS11 MSSQL,MySQL Database,,PHP,C/C++/Visual C++/G++/QT++,Com,DirectX,Open CV,EMGU CV , embedded System Development , [Raspberry PI]. ,html,Javascript,Jquery,Ajax.CSS , Networking ,Cyber security, Ethical Hacking You can see my professional profile at http://linkedin.com/in/johnsontaugustine Email : johnsonaugustine@live.com

Saturday, 19 January 2013

Next Palindrome number using c


#include <stdio.h>
#include <math.h>
#define TRUE 1

int main()
{
  long n, t, r = 0, c, d;

  printf("Enter an integer\n");
  scanf("%ld", &n);    /* n must be a natural number */

  while (TRUE)
  {
    n++;
    t = n;

    /* Calculating reverse of number */

    while(t)
    {
      r *= 10;  /* Compound assignment operator r*=10 => r=r*10 */
      r += t%10;
      t /= 10;
    }

    /* if reverse equals original then it is palindrome */

    if (r == n)
    {
      d = (int)sqrt(n);

      /* Checking prime */

      for (c = 2; c <= d; c++)
      {
        if (n%c == 0)
          break;
      }
      if (c == d+1)
        break;
    }
    r = 0;
  }

  printf("%ld\n",n);

  return 0;
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.