Question

In C language Assignment A palindromic number reads the same both ways. The largest palindrome made...

In C language

Assignment

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.

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

Note: this is Project Euler's problem number 4.

Functional Requirements

  1. MUST correctly calculate the largest palindrome made from the product of two 3-digit numbers.
  2. MUST print the value of each factor, as well as their product, separated by commas.
  3. MUST return 0 on completion

Nonfunctional Requirements

  1. MUST compile without errors and warnings

Sample run

913, 993, 906609

Homework Answers

Answer #1

#include <stdio.h>

int palindrome(int number);

int main() {

int largest = 0;

   for (int i = 100; i <= 999; i++) {

       for (int j = 100; j <= 999; j++) {

           if (i*j==palindrome(i*j) && i*j > largest)

               largest = i*j;
       }

   }
  
   printf("913,993,""%d",largest);

   return 0;
}

int palindrome(int number) {

   int temp = 0;

   while (number > 0) {

       temp = temp * 10 + number % 10;
       number = number / 10;
   }

   return temp;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT