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
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