answersLogoWhite

0

What is a c program to reverse a five digit number?

Updated: 8/11/2023
User Avatar

Abinashkhandelwal

Lvl 1
13y ago

Best Answer

#include <stdio.h>

int main(void){

// Local Declerations

int intNum;

int midDigit;

// Statements

printf("Enter a 5 digit integral number: ");

scanf("%d", &intNum);

//the assignment expression below is used to calculate the mid digit

oneDigit = (intNum % 1000) / 100;

printf("\nThe middle digit is: %d", oneDigit);

return 0;

}

User Avatar

Wiki User

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

Wiki User

14y ago

// Returns the sum of the left-most and right-most digits of num.

// If num contains only one digit, returns num.

unsigned int getSum(const unsigned int num) {

// Special case for single-digit numbers.

if(num <= 9) {

return num;

}

// We can find the right-most digit of num by modding it by 10.

const unsigned int rightmostDigit = num % 10;

// We can find the left-most digit of num by dividing it by 10^(numDigits-1)

const unsigned int numDigits = getNumDigits(num);

const unsigned int p = (unsigned int) pow(10.0, numDigits - 1);

const unsigned int leftmostDigit = num / p;

return rightmostDigit + leftmostDigit;

}

// Returns the number of digits in n

unsigned int getNumDigits(const unsigned int n) {

return ((unsigned int) log10(n) + 1);

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include

int main()
{
int original;
int original_backup;
int backward=0;


do
{
printf("Enter a five digit number, please!");
scanf("%d",&original);

}
while (original>99999 original < 10000);
/*this loop will ask for a new number as long as the user doesn't provide a five-digit one*/
/*note that if you remove it, the program will actually work for any number of digits*/

original_backup = original; /*this will remember the original number for later, as we will destroy it in the process*/

while(original) /*this loop actually turns it around (it will go as long as original is not zero*/
{
backward = backward * 10; /*shift the new number one place to the left and add a zero to the end*/
backward = backward + (original % 10); /* so we can add the last digit of the original number*/
original = original / 10; /*and delete it, so the loop actually checks four-digit number in the next iteration (and three-, two-, one-, zero-digit after that)*/

}

if(backward == original_backup) puts("The number is a palindrome.");
else printf("%d",backward);
return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

#include <iostream>

#include <string>

using std::cin;

using std::cout;

using std::endl;

using std::string;

int main()

{

const int numberOfDig = 5;

string num = "0";

cout << endl << "Enter a five digit number: ";

cin >> num;

string revNum = "00000";

for (int i = 0; i < numberOfDig; i++)

{

revNum[numberOfDig - i - 1] = num[i];

}

cout << endl << "You have entered: " << num

<< endl << "Reversed number is: " << revNum

<< endl;

system("PAUSE");

return 0;

}

OR a much simpler (not perfect) newbie method would be

#include<stdio.h>

#include<conio.h>

int main()

{

clrscr();

int a,b,c,d,e,f,g,i,h;

printf("enter a number");

//i supposed tht given numbers are vwxyz

scanf("%d",&a); //vwxyz

b=a/10000; //v

c=a%10000; //wxyz

d=c/1000; //w

e=c%1000; //xyz

f=e/100; //x

g=e%100; //yz

h=g/10; //y

i=g%10; //z

printf("reversed stuff is %d%d%d%d%d",i,h,f,d,b); //output is zyxwv

getch();

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is a c program to reverse a five digit number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How many five digit hexadecimal strings are there?

Considering the lowest five digit hexadecimal number is 10000 (65,536) and the highest is FFFFF (1,048,575), there are 983,040 different hexadecimal numbers that are five digits.


How is tensile strength of a metric bolt identified?

Many High Tensile bolts will have a number of raised strokes formed in the head of the bolt. Three or five are common and usually form a reverse triangle or reverse heptagon


A five digit no is entered through the keyboard write a program to obtain the reversed no and to determine whether the original no and reversed no is equal or not?

1) first you have to find the reverse of an integer.. code is given below, #include&lt;stdio.h&gt; void main() { int a,b,m,s=0; printf("enter the value of a"); scanf("%d",&amp;a); b=a; while(a!= 0) { m=a%10; s=s*10+m; a=a/10; } if(s == b) { printf("original number is equal to the reversed number"); } else { printf("original number is not equal to the reversed number");


What is the shell script program for adding five digit numbers?

It depends upon which language you intend to write your script, however 5 digit numbers are simply numeric value and any scripting language that supports basic arithmetic operators will be able to achieve this easily. The hardest part is converting the user input (which is typically a character sequence) into an actual number, however most scripting languages will provide some means of converting strings to numeric values.


Write a function that accept 5 digit number and return the sum of it to main?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; int func(void); void main(void) { clrscr(); printf("Enter five digit number: "); printf("nnnSum of entered number is %d",func()); getch(); } int func(void) { int b=0,a; while((a=getche())!='r') b+=a-=48; return b; }

Related questions

Can you find a five digit number which is four times its reverse?

87912 = 4 x 21978


What 5 digit number when multiplied by 4 yields the number the same five digits in reverse order?

The number is 21978. 21978 when multiplied by 4 which gives the result 87912 which is in reverse order.


What is a five digit number?

A five digit number is a number consisting of five digits. eg. 12345 54321 98765


What is the smallest five digit number having three digit?

All five digit numbers have three digits. The smallest five digit whole number is 10,000


What is the largest five-digit prime number?

The largest five-digit prime number is 99,991.


Which is the five digit odd number?

There are 45000 such numbers. None of them can be considered "the" five digit odd number.


The sum of digits of a two-digit number if five Find the number if the ten's digit is five more than the one's digit?

50


What is Geico's five digit insurance code number?

GEICO insurance company five digit code number


Is the product of a four digit and a one digit number always a five digit?

no


What is the smallest five digit number that can be rounded to 60000?

51111 is the smallest five digit number that can be rounded to 60000


If a five digit number is input through the keyboard write a program to calculate the sum of its digits?

If a five-digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example if the number that is input is 12391 then the output should be displayed as 23402. //Author::Mudasir Yaqoob..... #include&lt;stdio.h&gt; #include&lt;conio.h&gt; int main() { long number,t; int i=0; long temp[5]; printf("Enter the five digit number:\n\n"); scanf("%ld",&amp;number); while(i&lt;=4) { t=number%10+1; temp[i]=t; number=number/10; i++; } printf("Reverse number\n\n\n\n"); for(i=4;i&gt;=0;i--) { printf("%ld",temp[i]); } getch(); }


What is the least number of digits there can be in the quotient when you divide a five number digit number by a one digit number?

4