Question

C++ Write a program that checks whether the first digit of the entered number equals the...

C++

Write a program that checks whether the first digit of the entered number equals the last digit.

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

Answer:

Explanation:

last_digit variable stores the last digit using mod operator and then using while loop, removing the last digit one by one till n is greater than 0, the first_digit variable is assigned the first digit.

Then, both digits are matched and output is printed.

Code:


#include <iostream>

using namespace std;

int main()
{
int n;
cout<<"Enter the number: ";
cin>>n;
  
int last_digit = n%10;
int first_digit = n%10;
n = n/10;
  
while(n>0)
{
first_digit = n%10;
n = n/10;
}
if(first_digit==last_digit)
{
cout<<"First digit is equal to the Last digit"<<endl;
}
else
{
cout<<"First digit is not equal to the last digit"<<endl;
}

return 0;
}

Output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

Add a comment
Know the answer?
Add Answer to:
C++ Write a program that checks whether the first digit of the entered number equals the...
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
  • Write in Java Write code which checks validity of a 3-digit positive integer entered by the...

    Write in Java Write code which checks validity of a 3-digit positive integer entered by the user. The number is considered valid (true) if the sum of the first two digits is less than the last. Otherwise it is invalid (false).

  • Write a C program that counts the number of each digit entered by the user (Input...

    Write a C program that counts the number of each digit entered by the user (Input process should be ended using EOF character). You should use switch to compute the number of each digits. For each digit your program should print a line containing that number of adjacent asterisks. Sample Input1: 18218342850056D855599 Sample Outputi: 0** 3° 5*** 6° 7 g*** Sample Input: 77777445521056 Sample Output2: 0* 1 2° 3 45 S. 6° 8 9 Sample Output 3: Sample Input3: 782222231567799988001332092555...

  • Write a program that uses a random number generator to generate a two digit positive integer...

    Write a program that uses a random number generator to generate a two digit positive integer and allows the user to perform one or more of the following operations: a. Double the number. b. Reverse the digits of the number. c. Raise the number to the power of 2, 3, or 4. d. Sum the digits of the number. e. If the number is a two digit number, then raise the first digit to the power of the second digit....

  • 1. Write a program that takes a number as input and check whether the number is...

    1. Write a program that takes a number as input and check whether the number is positive, negative or zero. 2. Write a C++ program that prompts the user to enter a number and checks whether the entered number is even or odd. 3.  Using switch-case statement write a C++ program that prompts the user to enter 1, 2 or 3 and display "Red" if selection is 1, "Yellow" if selection is 2, or "Green" if selection is 3. 4. Write...

  • Program Instructions: Write a C++ program that uses a random number generator to generate a two...

    Program Instructions: Write a C++ program that uses a random number generator to generate a two digit positive integer and allows the user to perform one or more of the following operations: Double the number. Reverse the digits of the number. Raise the number to the power of 2, 3, or 4. Sum the digits of the number. If the number is a two digit number, then raise the first digit to the power of the second digit. If the...

  • Digit to WordsWrite a C program that asks the user for a two-digit number, then prints...

    Digit to WordsWrite a C program that asks the user for a two-digit number, then prints the English wordfor the number. Your program should loop until the user wants to quit.Example:Enter a two-digit number: 45You entered the number forty-five.Hint: Break the number into two digits. Use one switch statement to print the word for the firstdigit (“twenty,” “thirty,” and so forth). Use a second switch statement to print the word for thesecond digit. Don’t forget that the numbers between 11...

  • Write a program that prompts the user to enter an integer and checks whether the number...

    Write a program that prompts the user to enter an integer and checks whether the number is divisible by both 5 and 6, divisible by 5 or 6, or just one of them (but not both). SAMPLE OUTPUT Enter an integer: 10 Is 10 divisible by 5 and 6? False Is 10 divisible by 5 or 6? True Is 10 divisible by 5 or 6, but not both? True (Python programming language)

  • Write a C++ Program to Check Whether a character entered by user is Vowel or Consonant.

    Write a C++ Program to Check Whether a character entered by user is Vowel or Consonant.

  • Write a C program which calculates how many digits a number has and prints each digit...

    Write a C program which calculates how many digits a number has and prints each digit in reserve order with space in between(no space after the last digit). The number > 0 and has no more than 5 digits. (optional] It is better to write two functions. One is designed for printing number in reverse order and the other is for counting the number of digits. Given that the value of number (which is an int variable) is 12345, the...

  • 1. Write a complete C++ program named “CheckAmount” that accepts command line arguments. It checks whether...

    1. Write a complete C++ program named “CheckAmount” that accepts command line arguments. It checks whether there is a command line argument of “-amount” followed by an amount number. It will print out that number amount. For all other cases, it will print out -1. For example, if you run this program with correct arguments as follows, it will print out 1.99, 0.75 and 1.1 respectively CheckAmount -amount 1.99 CheckAmount -help -amount 0.75 CheckAmount -help -check -amount 1.1 -verbose And...

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