---
title: "Palindrome check in FORTRAN"
subject: "Computer Programming"
chapter: 11
key: "semester_1/computer_programming:fortran-palindrome"
source: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-palindrome
site: BCT Engineering
---

# Palindrome check in FORTRAN

Computer Programming · Chapter 11: Programming Language: FORTRAN

- Asked in: 2068 Chaitra, 8 marks
- Video: [Write a fortran program to check whether a number is palindrome or not.](https://www.youtube.com/watch?v=ygc6cMR5Vqw) — Super Century 
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-palindrome
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-11

## Question

Write a program in FORTRAN, to check whether a positive integer entered from the keyboard is a palindrome or not. (Hints: A number is palindrome if its reverse is equal to the number itself).

## Short answer

Reverse the integer: repeatedly take last digit (MOD 10), build rev = rev*10 + digit, divide by 10. If reverse equals original, it is a palindrome; e.g., 121 reversed gives 121.

## Answer

**Method.** Keep a copy of the number in M. Reverse it: take the last digit (`MOD(M,10)`), append it to REV (`REV = REV*10 + digit`), and drop it from M (`M/10`) until M becomes 0. The number is a palindrome if REV equals the original N.

```fortran
      PROGRAM PALIN
      INTEGER N, M, R, REV
      PRINT *, 'ENTER A POSITIVE INTEGER'
      READ *, N
      M = N
      REV = 0
   10 IF (M .GT. 0) THEN
         R = MOD(M, 10)
         REV = REV * 10 + R
         M = M / 10
         GO TO 10
      END IF
      IF (REV .EQ. N) THEN
         PRINT *, N, ' IS A PALINDROME'
      ELSE
         PRINT *, N, ' IS NOT A PALINDROME'
      END IF
      STOP
      END
```

**Trace for 121:** REV = 1, then 12, then 121; REV equals N, so it is a palindrome. For 123 the reverse is 321, so it is not.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which statement adds the last digit R to the reverse?
   A. REV = REV + R
   B. REV = REV * 10 + R
   C. REV = R / 10
   D. REV = MOD(REV,10)
   Answer: B. Multiplying by 10 shifts the digits left before appending the new one. (Key point: Building the reverse)

2. Why is the number copied to M before reversing?
   A. Because the original N is needed for comparison at the end
   B. To save memory
   C. Because MOD cannot use N
   D. To make N positive
   Answer: A. M is destroyed by repeated division; N stays unchanged for the final comparison. (Key point: Why copy to M)

3. When is the number a palindrome?
   A. REV equals the original N
   B. REV is greater than N
   C. REV is 0
   D. M is 1
   Answer: A. A palindrome reads the same reversed, so reverse equals the original. (Key point: Test)

4. What is the reverse of 123 and is it a palindrome?
   A. 321; no
   B. 123; yes
   C. 321; yes
   D. 32; no
   Answer: A. REV builds 3, 32, 321, which differs from 123. (Key point: Trace)

## Related in Computer Programming

- [Check triangular number](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Atriangular-number) — Computer Programming, chapter 5
- [Flowchart to reverse integer](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aflowchart-reverse-number) — Computer Programming, chapter 2
- [Palindrome string using function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apalindrome-string-function) — Computer Programming, chapter 7
- [Structure of a FORTRAN program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-structure) — Computer Programming, chapter 11, asked 5×
- [Quadratic equation roots in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-quadratic-roots) — Computer Programming, chapter 11, asked 2×
- [Sort array ascending in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-sort-ascending) — Computer Programming, chapter 11, asked 2×

## Related in other subjects

- [Equal positive and negative sequence impedances](https://www.bctengineer.com/question.md?key=semester_5%2Fpower_system_analysis_ii%3Astatic-circuit-positive-negative-equal) — Power System Analysis II, chapter 4
- [Prime number program: procedural and OOP](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aprime-procedural-oop) — Object Oriented Programming, chapter 1
- [8255 mode 1 keyboard and printer with decoding](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Appi-keyboard-printer-mode1-fig) — Instrumentation II, chapter 2
- [Keyboard and printer interface in 8255 mode 1](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Akeyboard-printer-mode1) — Instrumentation II, chapter 2
