Question

USE MATLAB: USE FOR AND WHILE LOOPS Write a program to check whether a number is...

USE MATLAB: USE FOR AND WHILE LOOPS

Write a program to check whether a number is a palindrome or not. Palindromes are numbers that read same backward and forward.

Test Data : Input a number: 121

Expected Output :

121 is a palindrome number.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

n = input("Input a number: ");
inputValue = n;
reversedInt = 0;
for i=1:inputValue
    reversedInt=reversedInt*10+mod(n,10);
    n=floor(n/10);
    if(n==0)
        break;
    end
end
if(reversedInt==inputValue)
    fprintf("%d is a palindrome number.\n",inputValue);
else
    fprintf("%d is not a palindrome number.\n",inputValue);
end

n = input("Input a number: ");
inputValue = n;
reversedInt = 0;
while(n!=0)
    reversedInt=reversedInt*10+mod(n,10);
    n=floor(n/10);
end
if(reversedInt==inputValue)
    fprintf("%d is a palindrome number.\n",inputValue);
else
    fprintf("%d is not a palindrome number.\n",inputValue);
end
Add a comment
Know the answer?
Add Answer to:
USE MATLAB: USE FOR AND WHILE LOOPS Write a program to check whether a number is...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USING FOR AND WHILE LOOPS-MATLAB) 6. Write a program to display the number in reverse order....

    USING FOR AND WHILE LOOPS-MATLAB) 6. Write a program to display the number in reverse order. Test Data : Input a number: 12345 Expected Output : The number in reverse order is : 54321

  • .using while loops(matlab) Write a program to display the sum of the series [ 9 +...

    .using while loops(matlab) Write a program to display the sum of the series [ 9 + 99 + 999 + 9999 ...] Test Data : Input the number or terms :5 Expected Output : 9 99 999 9999 99999 The sum of the series = 111105

  • Use Matlab to write a program to display the cube of the number up to a...

    Use Matlab to write a program to display the cube of the number up to a given integer. (USE BOTH FOR & WHILE LOOPS PLEASE) Test Data: Input number of terms : 5 Expected Output : Number is : 1 and cube of the 1 is :1 Number is : 2 and cube of the 2 is :8 Number is : 3 and cube of the 3 is :27 Number is : 4 and cube of the 4 is :64...

  • In C language, please use at least one user defined function, and show data validity check...

    In C language, please use at least one user defined function, and show data validity check for != integers 3) Write a program to find whether a given number is a Palindrome number (number that is same when you read from forward or backward). You need to take a long integer number from user as input and verify whether it's a number and positive or not. If the input is not valid (e.g., string or float) or positive, then notify...

  • Write a program using java that determines whether an input string is a palindrome; that is,...

    Write a program using java that determines whether an input string is a palindrome; that is, whether it can be read the same way forward and backward. At each point, you can read only one character of the input string; do not use an array to first store this string and then analyze it (except, possibly, in a stack implementation). Consider using multiple stacks. please type out the code :)

  • Write a program that reads each word from A1.txt and check if it's a palindrome or...

    Write a program that reads each word from A1.txt and check if it's a palindrome or not. Show your output in the file Bl.txt. The total number of words in the file can change. You must use c-string or character arrays. Using String datatype and strrev() function are not allowed in this problem. "A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward." (Wikipedia) Sample Input: series madam Sample Output: yes

  • Write a program that uses a recursive function to determine whether a string is a character-unit...

    Write a program that uses a recursive function to determine whether a string is a character-unit palindrome. Moreover, the options for doing case sensitive comparisons and not ignoring spaces are indicated with flags. For example "A nut for a jar of tuna" is a palindrome if spaces are ignored and not otherwise. "Step on no pets" is a palindrome whether spaces are ignored or not, but is not a palindrome if it is case sensitive. Background Palindromes are character sequences...

  • A palindrome is a number or a text phrase that reads the same backward as forward....

    A palindrome is a number or a text phrase that reads the same backward as forward. For example, each of the following six-digit integers is a palindrome: 123321, 555555, 455554, and 116611. Write a pseudocode and C++ program that reads in a six-digit integer and determines whether or not it is a palindrome. You must use the division and remainder operators. Assume input is correct (six-digit integer). Please don't use loops. Do it with only using if else.

  • Write a C Program that asks the user to input a string and then the user...

    Write a C Program that asks the user to input a string and then the user is prompted back whether the input string is a “Palindrome Word” or not. (A Palindrome Word reads the same backward or forward, eg. madam, racecar, etc.) Your program should contain a function that accepts the input string from the main function and returns a value indicating whether the input string is a Palindrome or not. Use Pointers to traverse the string.

  • Please Code in Java and follow the directions given Thanks Program required Directions .A palindrome is a str...

    Please Code in Java and follow the directions given Thanks Program required Directions .A palindrome is a string that reads the same forward and backward, i.e., the letters are the same whether you read them from right to left or from left to right. Examples: 3 a) radar à is a palindrome b)Able was I ere I saw Elba à is a palindrome e good à not a palindrome Write java program to read a line of text and tell...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT