Author Topic: C Program to print first 25 palindrome numbers in 3 digits system?  (Read 2257 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
wap to print first 25 palindrome numbers in 3 digits system?

Code:
//Source Code Listing


#include <stdio.h>

int IsNumberPalindrome(int n)
{
   int number;
   int digits[10], i, index;
   int palindrome;

   while(1)
   {
      number = n;
      index = 0;
      palindrome = 1;
      do
      {
         digits[index++] = n % 10;
         n = n / 10;
      } while(n > 0);

      for(i = 0; i < index / 2 + 1; i++)
      {
         if(digits[i] != digits[index - 1 - i])
         {
            palindrome = 0;
            break;
         }
      }

      return palindrome;
   }
}





void main()
{
   int i, count = 0;
   for(i = 100; i < 999; i++)
   {
      if(IsNumberPalindrome(i) == 1)
      {
         printf("%d\n", i);
         count++;
         if(count >= 25)
            break;
      }
   }
}

//output
/***

111
121
131
141
151
161
171
181
191
202
212
222
232
242
252
262
272
282
292
303
313
323
333
343

***/


 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1