Question

3) Write a program to find whether a given number is a Palindrome number (number that is same when you read from forward or bIn C language, please use at least one user defined function, and show data validity check for != integers

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

#include <stdio.h>

// main function definition
int main()
{
// To store number and reverse
long int num, temp, reverse;
// To store user choice to continue
char choice;

// Loops till user choice is not 'n' or 'N'
do
{
// Loops till valid number entered by the user
do
{
// Accepts a number
printf("\n Key in a number to check: ");
scanf("%d", &num);

// Checks if the number is less than or equals to 0 then display error message
// asks the number to re enter
if(num <= 0)
printf("\n The number %d is not valid.", num);

// Otherwise valid number come out of the loop
else
break;
}while(1);// End of do - while loop

// Stores the number in temp
temp = num;

// Re sets the reverse to 0 for every number
reverse = 0;

// Loops till temp number not equals to 0
// to calculate reverse
while (temp != 0)
{
// Calculates the reverse by multiplying the reverse number with 10
// and adds the remainder of the number
reverse = reverse * 10 + temp % 10;
// Calculates the quotient
temp /= 10;
}// End of while loop

// Checks if the original number is equals to reverse number then palindrome
if (num == reverse)
printf("%d is a palindrome number.\n", num);

// Otherwise the original number is not equals to reverse number then not palindrome
else
printf("%d not a palindrome number.\n", num);

// Clears the console
fflush(stdin);
// Accepts user choice to continue
printf("\n Do you want to continue(y/n)? ");
scanf("%c", &choice);

// Checks if user choice is 'N' or 'n' then come out of the loop
if(choice == 'N' || choice == 'n')
break;
}while(1);// End of do - while loop
printf("\n Good bye!!");
return 0;
}// End of main function

Sample Output:

Key in a number to check: -23

The number -23 is not valid.
Key in a number to check: 123454321
123454321 is a palindrome number.

Do you want to continue(y/n)? y

Key in a number to check: 456734
456734 not a palindrome number.

Do you want to continue(y/n)? n

Good bye!!

Add a comment
Know the answer?
Add Answer to:
In C language, please use at least one user defined function, and show data validity check...
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
  • C language: Write a program that uses a function to check if a user entered string...

    C language: Write a program that uses a function to check if a user entered string is a palindrome. Based on the return value of the function, the results are printed in the main() function. (do not print results in function to check for palindrome) A palindrome reads the same forward as backward for example tacocat or civic.

  • In this assignment, you must write a C program to check the validity of a Sudoku solution. You must at least do the foll...

    In this assignment, you must write a C program to check the validity of a Sudoku solution. You must at least do the following: 1- Ask the user to provide a minimum of first two rows of the Sudoku grid. For the rest of the entries, you should use a random number generator. 2- Use appropriate logic to make sure the random number generator generates a distinct set of valid integers! 3- It should be a console-based, yet convenient and...

  • In C:Write a program that can determine whether a user input is a binary number or...

    In C:Write a program that can determine whether a user input is a binary number or not. (1, 2, 3, 8, 13) Write a program that accomplishes all of the following: Greets the user and informs them that the program will determine whether an input from the user is a valid binary number or not (e.g., consisting of only 0’s and/or 1’s). Accept an integer input from the user. Assume that the user provides a valid numeric input that will...

  • This lab will give you a practice with both queue and stack ADTs. In this work,...

    This lab will give you a practice with both queue and stack ADTs. In this work, you are to determine if an input string is a palindrome. A string of characters is a palindrome if and only if it reads the same forward and backward. Examples: eye, abba, civic, radar, and so on. Sample Output: Please enter a string of characters: abba The given string is a palindrome. Want to examine another string? (y/n): y Please enter a string of...

  • Language: C++ PLEASE INCLUDE SCREENSHOT OF OUTPUT In this assignment, you will consider the problem of organizing a collection of computer user-ids and passwords. Each time a user logs in to the syste...

    Language: C++ PLEASE INCLUDE SCREENSHOT OF OUTPUT In this assignment, you will consider the problem of organizing a collection of computer user-ids and passwords. Each time a user logs in to the system by entering his or her user-id and a secret password, the system must check the validity of this user-id and password to verify that this is a legitimate user. Because this validation must be done many times each day, it is necessary to structure this information in...

  • with the correct answer please 5. Write a program in C++ that will perform the operation...

    with the correct answer please 5. Write a program in C++ that will perform the operation of a simple CALCULATOR. But its output will be as shown in the output Screen-short. Three(3) Marks Guideline for developing the application. Input Output 1. Start program with asking The output will be question whether user is willing 1. The chosen Operator to continue or not. 2. Calculated result 2. If answer is Yes, Like:- System will ask for c\Users\Alamgir Documents\Visual Studio 2008 Proje....

  • Modify the code, so that it will check the various user inputs for validity (e.g., months...

    Modify the code, so that it will check the various user inputs for validity (e.g., months being between 1 - 12), - if invalid value was entered, ask user to enter a new (& correct) value, - check to see if new value is valid - if valid allow the user to continue. - if still not valid repeat this process, until valid value is entered __________________________________________________________________________________________________ QUESTION: Desc: This program creates a painting order receipt. Ask for the following...

  • C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include ...

    C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include <stdio.h> int main() { int fries; // A flag denoting whether they want fries or not. char bacon; // A character for storing their bacon preference. double cost = 0.0; // The total cost of their meal, initialized to start at 0.0 int choice; // A variable new to version 2, choice is an int that will store the // user's menu choice. It will also serve as our loop control...

  • C PROGRAMMING You must write a C program to check the validity of a Sudoku solution. Follow the link to know more about...

    C PROGRAMMING You must write a C program to check the validity of a Sudoku solution. Follow the link to know more about Sudoku: https://www.bigfishgames.com/blog/how-to-solve-sudoku-puzzles-quickly-andreliably/ You must at least do the following: 1- Ask the user to provide a minimum of first two rows of the Sudoku grid. For the rest of the entries, you should use random number generator. 2- Use appropriate logic to make sure random number generator generates distinct set of valid integers! 3- It should be...

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
ADVERTISEMENT