Encrypting your link and protect the link from viruses, malware, thief, etc! Made your link safe to visit.

A palindrome is a number or a text phrase that reads the same backwards as forwards. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write a C++ program that reads in a five-digit integer and determines whether it is a palindrome .


Question:


A palindrome is a number or a text phrase that reads the same backwards as forwards. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write a C++ program that reads in a five-digit integer and determines whether it is a palindrome .


Answer:


Step 1

PROGRAMING CODE:

 

#include <stdio.h>

int main() {
  int n, a, b, c, d, e;
  int digit = 0;

  printf( "Enter one 5 digit number: \n" );
  scanf( "%d", &n );

  a = n / 10000;
  b = n / 1000 % 10;
  c = n / 100 % 10;
  d = n / 10 % 10;
  e = n % 10;

  if ( a == e && b == d ) {
    printf( "Palindrome!\n" );
  }

  if ( a != e || b != d ) {
    printf( "Not a palindrome.. :(\n" );
  }

  return 0;
}

PROGRAM SCREENSHOT:

Computer Science homework question answer, step 1, image 1

Step 2

Computer Science homework question answer, step 2, image 1

Computer Science homework question answer, step 2, image 2

Computer Science homework question answer, step 2, image 3

Computer Science homework question answer, step 2, image 4

ST

Search This Blog

Labels

Report Abuse

Contributors