Print number in reverse order

Page 1 of 1

9 Replies - 29701 Views - Last Post: 05 November 2010 - 04:06 AM Rate Topic: -----

#1 noor.mz143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 291
  • View blog
  • Posts: 1,900
  • Joined: 25-October 06

Re: Print number in reverse order

Posted 06 February 2007 - 12:47 PM

View Postnoor.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.
Was This Post Helpful? 1
  • +
  • -

#3 AmitTheInfinity  Icon User is offline

  • C Surfing ∞
  • member icon

Reputation: 119
  • View blog
  • Posts: 1,563
  • Joined: 25-January 07

Re: Print number in reverse order

Posted 07 February 2007 - 04:09 AM

View Postnoor.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. :)
Was This Post Helpful? 1
  • +
  • -

#4 linkman124  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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?

View Postnoor.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++

Was This Post Helpful? 0
  • +
  • -

#5 Soura  Icon User is offline

  • New D.I.C Head

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

Re: Print number in reverse order

Posted 25 September 2008 - 08:26 PM

View Postnoor.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();
}



Please try this.

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

Was This Post Helpful? 0
  • +
  • -

#6 Soura  Icon User is offline

  • New D.I.C Head

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

Re: Print number in reverse order

Posted 26 September 2008 - 09:52 PM

View Postnoor.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*/


Please try this.
Was This Post Helpful? 0
  • +
  • -

#7 sajibma  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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;
	printf("input your number:\n..............\n");
	scanf("%d",&num);
	printf("your reverse number is:\n"); 
	for(;num>0;)
	{sum=num%10;
	printf("%d",sum);
	num=num/10;
	
	}printf("\n..................\n");


}


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

:code:

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

Was This Post Helpful? 0
  • +
  • -

#8 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#9 C++ Programmer  Icon User is offline

  • D.I.C Addict
  • member icon

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

Re: Print number in reverse order

Posted 05 November 2010 - 03:12 AM

Yes.
Was This Post Helpful? 0
  • +
  • -

#10 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6091
  • View blog
  • Posts: 23,606
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1