Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,231 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,843 people online right now. Registration is fast and FREE... Join Now!




Print number in reverse order

 
Reply to this topicStart new topic

Print number in reverse order

noor.mz143
6 Feb, 2007 - 11:41 AM
Post #1

New D.I.C Head
*

Joined: 6 Feb, 2007
Posts: 1


My Contributions
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++

User is offlineProfile CardPM
+Quote Post

horace
RE: Print Number In Reverse Order
6 Feb, 2007 - 11:47 AM
Post #2

D.I.C Addict
Group Icon

Joined: 25 Oct, 2006
Posts: 573



Thanked: 4 times
Dream Kudos: 50
My Contributions
QUOTE(noor.mz143 @ 6 Feb, 2007 - 07: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++


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.
User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Print Number In Reverse Order
7 Feb, 2007 - 03:09 AM
Post #3

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,026



Thanked: 35 times
Dream Kudos: 125
My Contributions
QUOTE(noor.mz143 @ 7 Feb, 2007 - 01:11 AM) *

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

CODE


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. smile.gif
User is offlineProfile CardPM
+Quote Post

linkman124
RE: Print Number In Reverse Order
25 Jun, 2008 - 02:03 PM
Post #4

New D.I.C Head
*

Joined: 25 Jun, 2008
Posts: 1

can u give me the code for that?

QUOTE(noor.mz143 @ 6 Feb, 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++



User is offlineProfile CardPM
+Quote Post

Soura
RE: Print Number In Reverse Order
25 Sep, 2008 - 07:26 PM
Post #5

New D.I.C Head
*

Joined: 24 Sep, 2008
Posts: 27


My Contributions
QUOTE(noor.mz143 @ 6 Feb, 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++


The program is-

CODE
/*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();
}


Please try this.

This post has been edited by Soura: 25 Sep, 2008 - 07:27 PM
User is offlineProfile CardPM
+Quote Post

Soura
RE: Print Number In Reverse Order
26 Sep, 2008 - 08:52 PM
Post #6

New D.I.C Head
*

Joined: 24 Sep, 2008
Posts: 27


My Contributions
QUOTE(noor.mz143 @ 6 Feb, 2007 - 12:41 PM) *


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-
CODE
/*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*/

Please try this.

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 03:25PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month