Question

(Do algorithm and flowchart) Q1 Write 2 functions: int reverse (int) which returns reverse of a...

(Do algorithm and flowchart)
Q1
Write 2 functions: int reverse (int) which returns reverse of a number and int diff(int, int) which returns difference of two numbers. Using this Write a program to find whether a number given as input is palindrome or not
0 0
Add a comment Improve this question Transcribed image text
Answer #1

As mentioned that only algorithm and flowchart is needed for the question the solution to the problem goes as follows:

1) Reverse function.

algorithm: int reverse (int)

input: An integer value let say numb.

step1: read the value of numb that is passed as the parameter.

step2: initialize reverse_num =0

step3: start a loop that while numb>0

                    (i) Multiply the reverse_num by 10 and add remainder of numb divided by 10 to reverse_num

                                reverse_num = reverse_num * 10 + numb%10;

                    (ii) Divide the numb by 10

           end of the loop

step4: return reverse_num

2) Difference function

algorithm: int diff(int, int)

input: two integer values num1 and num2

step1: Read the values of the integers passed as the parameters.

step2: initialize difference = 0

step3: difference = num1 -num2 // abs(num1-num2) can be used if only positive value of difference is required.

step4: return difference

# Checking palindrome using above two functions:

Algorithm:

input: an integer value let say num

step1: Read the value of integer num.

step1: pass num to the reverse function we wrote above // int reverse( int num)

step3: Step 2 will return us an integer reverse_num

step4: Pass num and reverse_num as the parameter to the difference function we wrote above // int diff(int num, int reverse_num)

step5: now step 4 will return us an integer difference

                      if(difference==0):

                              print that the number is a palindrome

                      else:

                               print the number is not a palindrome

End of the program.

Add a comment
Know the answer?
Add Answer to:
(Do algorithm and flowchart) Q1 Write 2 functions: int reverse (int) which returns reverse of a...
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 2 functions: int reverse (int) which returns reverse of a number and int diff(int, int)...

    Write 2 functions: int reverse (int) which returns reverse of a number and int diff(int, int) which returns difference of two numbers. Using this Write a program to find whether a number given as input is palindrome or not

  • Q1: Write an algorithm and sketch the flowchart to read 20 numbers for x and finding...

    Q1: Write an algorithm and sketch the flowchart to read 20 numbers for x and finding the number of times that the number 100 is repeated between these numbers. (12 marks) Q2: What is the difference between prefix decrementer (- - i) and postfix decrementer (i - -) explain using examples. Q3: C++ includes a very special operator called the ternary operator. Explain with example how this operator used? Q4: Write C++ Program which output this result ******50 *****500 ****5000...

  • Q4. Write an algorithm, draw the flowchart and write a C++ program to • Read the...

    Q4. Write an algorithm, draw the flowchart and write a C++ program to • Read the Number and Letter from the user • Check the number and letter then print the corresponding month name as given in Table Q4 using IF ELSE STATEMENT. Table: Q4 Number and Letter Month Name JANUARY 2 F FEBRAURY 3 M MARCH 4 A APRIL Other numbers Invalid Input 1J Sample Output: Enter the value of number:1 Enter the value of letter:) JANUARY Algorithm: Flowchart:...

  • (write algorithm and draw flowchart) for this question Write a C program which has a function...

    (write algorithm and draw flowchart) for this question Write a C program which has a function that takes two numbers and find the largest and the smallest number and find the result of the largest power of smallest.(for example If the entered numbers are 6 and 3 the result is 6³)

  • Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true...

    Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true if that integer is palindrome, otherwise it returns false. The function also prints the digits of the integer in reverse order in which they were found. Write a main) function that reads an integer, calls the function is whether the integer is a palindrome or not. Palindrome), and prints Sample input/output: nter an integer: 23434 nter an integer 23432 3434 is not a palindrome...

  • Q1. Write an algorithm (pseudocode or flowchart) for the following problem. Input: Eight integers Output: the...

    Q1. Write an algorithm (pseudocode or flowchart) for the following problem. Input: Eight integers Output: the sum of even numbers only. Example: Let the eight integers are 2, 9, 3, 20,5,17, 10, 6 then S = 2+20+10+6 = 38

  • (Palindrome integer) Write the functions with the following headers: # Return the reversal of an integer,...

    (Palindrome integer) Write the functions with the following headers: # Return the reversal of an integer, e.g. reverse(456) returns # 654 def reverse(number): # Return true if number is a palindrome def isPalindrome(number): Use the reverse function to implement isPalindrome. A number is a palindrome if its reversal is the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome.

  • Write a C program, containing the following functions. Function int recursive_fibonacci(int n) computes and returns the...

    Write a C program, containing the following functions. Function int recursive_fibonacci(int n) computes and returns the nth F(n) using recursive algorithm (i.e., recursive function call). Fibonacci numbers are defined by F(1)=F(2)=1, F(i) = F(i-1)+F(i-2), i=2,… . Function int iterative_fibonacci(int n) computes and returns the nth Fibonacci number F(n) using iterative algorithm (i.e., loop). The main function measures the memory usage and run time of iterative_fibonacci(40) and recursive_fibonacci(40), and does the comparison. To capture the execution time by millisecond, it needs...

  • C# Design and implement a program (name it PalindromeInteger), to check if an integer value is...

    C# Design and implement a program (name it PalindromeInteger), to check if an integer value is a palindrome or not, using 2 methods (reverse and isPalindrome) specified as follows: Method reverse(int number) takes integer number and returns number in reverse order. The method mathematically reverses the number. Method isPalindrome(int number) takes integer number and returns true if the number is palindrome; false otherwise. Use method reverse() to implement method isPalindrome(). Notice that an integer value is palindrome if the value...

  • C++ Design and implement a program (name it PalindromeInteger), to check if an integer value is...

    C++ Design and implement a program (name it PalindromeInteger), to check if an integer value is a palindrome or not, using 2 methods (reverse and isPalindrome) specified as follows: Method reverse(int number) takes integer number and returns number in reverse order. The method mathematically reverses the number. Method isPalindrome(int number) takes integer number and returns true if the number is palindrome; false otherwise. Use method reverse() to implement method isPalindrome(). Notice that an integer value is palindrome if the value...

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