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.
(Do algorithm and flowchart) Q1 Write 2 functions: int reverse (int) which returns reverse of a...
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 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 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 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 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 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, 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 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...
(a) Write a recursive function int find(const int A[], int n, int x); which returns the first index i = 0, . . . , n − 1 such that A[i] == x, or n if it is not found. (b) Write a recursive function int rfind(const int A[], int n, int x); which returns the last index i = 0, . . . , n − 1 such that A[i] == x, or n if it is not found....
c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input: an int output: boolean function: Return true if the number is a prime number and return false otherwise */ //TO DO ************************************** /* Write a function checkPrime such that input: an array of int and size of array output: nothing function: Display the prime numbers of the array */ //TO DO ************************************** /* Write a function SumofPrimes such that input: an int output: nothing...