answersLogoWhite

0


Best Answer

//Reverse of the Number

#include<stdio.h>

#include<conio.h>

int main ()

{

int num,mod,rev=0;

printf("Enter a number:");

scanf("%d", &num);

while (num>0)

{

mod=num%10;

rev=(rev*10)+mod;

num=num/10;

}

printf("Reverse of the given number: %d", rev);

getchar();

return 0;

}

// alternative solution based on reversing the alphanumeric representation of

// the number:

void rev(int me) {

char alpha[32];

sprintf(alpha, "%d", me);

for (const char* cp = alpha + strlen(alpha) - 1; cp >= alpha; --cp) {

putchar(cp); }

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

suppose you are given the number
9254

In order to reverse it, you must eliminate each value and reverse it.
For example,

9254 / 1000 = 9
9254 % 1000 = 254

then
254 / 100 = 2
254 % 100 = 54

then
54 / 10 = 5
54 % 10 = 4

and your final digit is 4.

I will leave it up to you to figure out how to implement this, but that is the algorithm for extracting digits.
It should be clear how to use loops to abstract this problem into a "reverse" function.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

#include

Main()

{

Int num,r,rev=0;

Printf("enter a number");

Scanf("%d",&num);

While(num>0)

{

r=num%10;

rev=rev*10+r

num=num/10;

}

Printf("%d",rev);

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#include <stdio.h>

void main() //Defining main function

{

int number, modulus, reverse; //Integer Declaration

reverse = 0; //Initialization

printf("Enter a number \n");

scanf("%d", &number);

while(number != 0)

{

modulus = number % 10;

reverse = (reverse * 10) + modulus;

number =number / 10;

}

printf("The reversed number is %d", reverse);

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

/*C Program to Enter 5 Number at a time & Display them in Reverse Order of the input*/

#include<stdio.h>

#include<conio.h>

void main()

{

int i, x[5];

clrscr();

for (i=0;i<5;i++)

{

printf("Enter the number\n");

scanf("%d",&x[i]);

}

printf("\nThe reverse order is\n");

for (i=4;i>=0;i--)

{

printf("\n%d",x[i]);

}

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

1. Convert the number to a string.

2. Reverse the characters

3. Drop any leading zeros on the new string

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to find the reverse of a given number with help of function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you Write a C program to reverse an Integer number.?

Reference:cprogramming-bd.com/c_page2.aspx# reverse number


How do you Write a program in 'c' language which accepts int numbers from the users print its reverse number x function which return value?

question clarity


How you write a program in c plus plus to print plaindromic numbers from 1 to n?

To check if a number is a palindrome, reverse the number and see if it is equal to the original number. If so, the number is a palindrome, otherwise it is not. To reverse a number, use the following function: int reverse(int num, int base=10) { int reverse=0; while( num ) { reverse*=base; reverse+=num%base; num/=base; } return(reverse); }


Write a program that read phrase and print the number of lower-case letter in it using function of counting?

write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program


How can I write a program to display prime numbers from 1 to 100?

Write a function that implements an algorithm that checks to see if a particular integer is prime (returning a boolean). Write a program that uses that function on each number from 1 to 100, and if true, displays that number.


Write a Program to convert decimal number into hexadecimal no without using function and string?

This is not a question.


How do you write a program that outputs a given characters in reverse?

write the javascript code to display the reverse no. of given no. (e.g. 247 reverse of 742)


Write a function to reverse a string and to display it?

Yes.


How to write a program in python to print the reverse of a number?

In python, type the following into a document. NOTE: Sentences following a # symbol are comments, and are not necessary for the program to run. #!/usr/bin/python #This program takes a input from a user and reverses it. number = input("Type a number: ") #This takes input from a user. a = len(number) #This finds the length of the number reverse = "" #This sets the variable reverse to an empty string. for i in number: a = a-1 #The places in a string start from 0. The last value will be the length minus 1.reverse = reverse + number[a] #Makes the number's last digit the new string's first. print("The reverse of", number, "is", reverse + ".") #prints the resulting string. This program will take any sequence of characters and reverse them. The final value is a string, but if an integer is needed, one needs only to add the line reverse = int(reverse) above the print statement. However, this will stop the program from being able to reverse strings, as it is not possible to convert a string to an integer if it is not a number.


Where do we write main function in a c program?

Into the source program.


Write the program in Linux to find the reverse of any string?

i am sam


Write a program to read your name and reverse it using arrays?

abdulrahman