Example Code

Check if Number is a Palindrome

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

Overview
This VI takes an integer number from the user and determines if it is a palindrome or not.


Description
A palindrome is a number that is the same both forwards and backwards. The "Parse Number into 1D Array" community example was used to parse the input number into a 1D array of individual digits. Using this array, a comparison can be made with a reversed version of the array (Reverse 1D Array function), in order to determine if the number is identical both forwards and backwards. Since two arrays are being compared, the Compare Aggregates option of Comparison Mode was used for the Equal? function.


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Set the input
  2. Click run and view the results

 

Additional Information or References
VI Block Diagram

 Block Diagram.png

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

dK

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Zwired1
Active Participant
Active Participant
on

Another way....

Convert to string, compare the reversed string to original version.

palindrome_BD.PNG

[dk]
Member
Member
on

Yep, that is much simpler! Thanks!

dK