Question

Write a program to reverse an integer number by using a function called reverse. The program reads in an integer number and prints its reverse order. Note that the function receives the number via a pointer, and uses the pointer to write the reverse number on the main function.Bonus Problem: Number Reverser reverse c Write a program to reverse an integer number by using a function called reverse. The program reads in an integer number and prints its reverse order. Note that the function receives the number via a pointer, and uses the pointer to write the reverse number on the main function Implement this function: void reverse (int *n) Here is an example of the program output. Enter a number to reverse 1234 Reversed number is 4321

The function MUST be used AS IS:

void reverse(int *n)

Language in C

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

#include <stdio.h>
void reverse(int *n){
int reversenum = 0;
       while(*n > 0){
           int r = *n % 10;
           reversenum = reversenum * 10 + r;
           *n = *n / 10;
       }
   *n = reversenum;
}

int main()
{
int n;
printf("Enter a number to reverse: ");
scanf("%d", &n);
reverse(&n);
printf("Reversed number is %d\n", n);
return 0;
}

Output:

sh-4.2$ gcc -o main *.c                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                           

Enter a number to reverse: 1234                                                                                                                                                                                                                                        

Reversed number is 4321

Add a comment
Know the answer?
Add Answer to:
Write a program to reverse an integer number by using a function called reverse. The program...
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
  • 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments

    9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N  (that is not more than 50) from standard input and then reads N  integers from a file named...

  • 1. Palindrome Write a program that prompts the user for a positive integer number and output whet...

    Language is C 1. Palindrome Write a program that prompts the user for a positive integer number and output whether the number is a palindrome or not. A palindrome number is a number that is the same when reversed. For example, 12321 is a palindrome; 1234 is not a palindromoe. You will write a function named as palindrome. The function will have two arguments, number and isPalindrome. Both arguments are pass-by-reference. The argument number is a pointer to a variable...

  • Write a function to reverse an integer using numeric operators and without using any arrays or...

    Write a function to reverse an integer using numeric operators and without using any arrays or other data structures. The signature of the function is: int f(int n) Examples if the input integer is return 1234 4321 12005 50021 1 1 1000 1 0 0 -12345 -54321 by java

  • use c++ language, keep it simple i am using code block Exercise #2: Digitise a number...

    use c++ language, keep it simple i am using code block Exercise #2: Digitise a number Write the function digitiselint, int[]) of type int, which takes an integer N and finds all the digits of that integer and save them in an array. The function then returns the number of digits in N. Write the main() program that reads an integer, calls the function digitisel ), and prints the digits in reverse order. Sample input/output: Enter an integer: 2309456 The...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • Write a program that contains the function measure() that is to accept a long integer number...

    Write a program that contains the function measure() that is to accept a long integer number total and the addresses of the integer variables inches, feet, yards, and miles. The passed long integer represents the total number of inches, and the function is to determine the number of miles, yards, feet, and inches in the passed value, writing these values directly into the respective variables declared in the calling function. This function will be called from the main program and...

  • Consider the following program that reads a number of nonnegative integers into an array and prints...

    Consider the following program that reads a number of nonnegative integers into an array and prints the contents of the array.   Complete the missing parts, add new function prototypes and function definitions, and test the program several times. Add the following to the program: Write a void function that prints the list of nonnegative integers in reverse. Write a void function that prints all the numbers stored in the list that are greater than 10. It will also print the...

  • help me solving this both please in c++ language 6 Write function max(int al Lint n)...

    help me solving this both please in c++ language 6 Write function max(int al Lint n) that receives an array of integer and its length, it returns the maximum number in that array. Test your function in main. 7) Write functin reverse (char x[ .int n) that reieves an array of characters and reverse the order of its elements. Test this function in main.

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

  • Done in C++ using visual studio 1. Write a program with one additional function called int[]...

    Done in C++ using visual studio 1. Write a program with one additional function called int[] reverseArray(int array). This function will receive an array from main and then reverse and should return the reversed array to the main to print out. Use a single array and a single loop, you’re are neither allowed to print out just in reverse order nor allowed to use another array variable to store the original array in reverse order. 2. Write a program which...

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