SnapTimes

News In A Snap!!

C++ Programs: Find the Largest Palindrome made from the Product of Two 3-digit Numbers

June 2, 2015

What is a Palindrome?

A word, phrase, or sequence that reads the same backwards as forwards, e.g. madam or nurses run.

Code


/* Find the largest palindrome made from the product of two 3-digit numbers

*/

#include <iostream.h>

#include<conio.h>

int isPalindrome(int number);

int main() {

clrscr();

long largest = 0;

for (int i=999; i>0; i--)

for (int j=999; j>0; j--)

if(isPalindrome(i*j))

if (i*j > largest)

largest = i*j;

cout << "Largest palindrome is " << largest;

getch();

return 0;

}

int isPalindrome(int number) {

int original = number;

int reverse = 0;

for (int i=0; i<=number; i++) {

int remain = number%10;

number = number/10;

reverse = reverse*10 + remain;

}

return reverse == original;

}

palin


SnapTimes.in | Get Tech Addicted...
About Us | Contact Us | ©2017