# Print number in reverse order

Page 1 of 1

## 9 Replies - 30133 Views - Last Post: 05 November 2010 - 04:06 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=23644&amp;s=caa20bdf611a4b624700f0c015ffd83b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 noor.mz143

Reputation: 0
• Posts: 1
• Joined: 06-February 07

# Print number in reverse order

Posted 06 February 2007 - 12:41 PM

tell me how to write a program to scnaf number and print it in reverse order either in C or C++ thanks.

also how to write a program to find the sum of digits enterd by the user in C or C++

Is This A Good Question/Topic? 0

## Replies To: Print number in reverse order

### #2 horace

• D.I.C Lover

Reputation: 542
• Posts: 2,853
• Joined: 25-October 06

## Re: Print number in reverse order

Posted 06 February 2007 - 12:47 PM

noor.mz143, on 6 Feb, 2007 - 07:41 PM, said:

tell me how to write a program to scnaf number and print it in reverse order either in C or C++ thanks.

also how to write a program to find the sum of digits enterd by the user in C or C++

you could read the digits character by character into an array until newline is found and then print the array in the reverse order. While reading the digits you could form a sum at the same time by adding the digits.

### #3 AmitTheInfinity

• C Surfing ∞

Reputation: 119
• Posts: 1,565
• Joined: 25-January 07

## Re: Print number in reverse order

Posted 07 February 2007 - 04:09 AM

noor.mz143, on 7 Feb, 2007 - 01:11 AM, said:

tell me how to write a program to scnaf number and print it in reverse order either in C or C++ thanks.

also how to write a program to find the sum of digits enterd by the user in C or C++

You can take integer from user and use "div and mod" method for reversing as well as calulating sum of digits in a number.

Well have a look on this

```
void main()
{
int num,sumOfDigits=0;
printf("Enter Number : ");
scanf("%d",&num);
printf("Reversed Number is : ");
while(num>0)
{
sumOfDigits += num%10;
printf("%d",num%10);
num /=10;
}
printf("\nSum Of Digits is : %d",sumOfDigits);
}

```

now validations like numbers should be within range of integer and it should be positive etc etc.... you can take care of it.

Reputation: 0
• Posts: 1
• Joined: 25-June 08

## Re: Print number in reverse order

Posted 25 June 2008 - 03:03 PM

can u give me the code for that?

noor.mz143, on 6 Feb, 2007 - 12:41 PM, said:

tell me how to write a program to scnaf number and print it in reverse order either in C or C++ thanks.

also how to write a program to find the sum of digits enterd by the user in C or C++

### #5 Soura

Reputation: 0
• Posts: 27
• Joined: 24-September 08

## Re: Print number in reverse order

Posted 25 September 2008 - 08:26 PM

noor.mz143, on 6 Feb, 2007 - 12:41 PM, said:

tell me how to write a program to scnaf number and print it in reverse order either in C or C++ thanks.

also how to write a program to find the sum of digits enterd by the user in C or C++

The program is-

```/*Reverse No.*/
#include<stdio.h>
# include<conio.h>
# include<iostream.h>

main()
{
int a,n,s=0,t;
printf("Enter the number=");
scanf("%d", &a);
for(n=a;n!=0;n=n/10)
{
t=n%10;
s=(s*10+t);
}
printf("The Reverse No. is %d", s);
getch();
}

```

This post has been edited by Soura: 25 September 2008 - 08:27 PM

### #6 Soura

Reputation: 0
• Posts: 27
• Joined: 24-September 08

## Re: Print number in reverse order

Posted 26 September 2008 - 09:52 PM

noor.mz143, on 6 Feb, 2007 - 12:41 PM, said:

also how to write a program to find the sum of digits enterd by the user in C or C++

The program to find the sum of the no.s-
```/*Sum of the digits of a given no.*/

#include<stdio.h>
#include<conio.h>
#include<iostream.h>

main()
{
int n;
int s=0, r;
printf("Enter the no...");
scanf("%d", &n);
while(n>0)
{
r=n%10;
s=s+r;
n=n/10;
}
printf("The SUM VALUE is=%d",s);
getch();
}

/*end of main*/

```

### #7 sajibma

Reputation: 0
• Posts: 1
• Joined: 05-November 10

## Re: Print number in reverse order

Posted 05 November 2010 - 02:30 AM

```#include <stdio.h>

void main()
{
int num,sum=0;
scanf("%d",&num);
for(;num>0;)
{sum=num%10;
printf("%d",sum);
num=num/10;

}printf("\n..................\n");

}
```

MOD EDIT: When posting code...USE CODE TAGS!!!

This post has been edited by JackOfAllTrades: 05 November 2010 - 04:05 AM

### #8 janotte

• code > sword

Reputation: 990
• Posts: 5,141
• Joined: 28-September 06

## Re: Print number in reverse order

Posted 05 November 2010 - 03:02 AM

Second necro revival on this thread (and with the added joy of absent code tags)

Should we lock this one down because it seems it will never die otherwise?

### #9 C++ Programmer

Reputation: 20
• Posts: 548
• Joined: 12-June 08

## Re: Print number in reverse order

Posted 05 November 2010 - 03:12 AM

Yes.

• Saucy!

Reputation: 6226
• Posts: 23,978
• Joined: 23-August 08

## Re: Print number in reverse order

Posted 05 November 2010 - 04:06 AM

Agreed. If we could build a house on top of this topic we could reshoot Poltergeist 2 here.