Print number in reverse order
Page 1 of 19 Replies - 29188 Views - Last Post: 05 November 2010 - 04:06 AM
#1
Print number in reverse order
Posted 06 February 2007 - 12:41 PM
also how to write a program to find the sum of digits enterd by the user in C or C++
Replies To: Print number in reverse order
#2
Re: Print number in reverse order
Posted 06 February 2007 - 12:47 PM
noor.mz143, on 6 Feb, 2007 - 07:41 PM, said:
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
Re: Print number in reverse order
Posted 07 February 2007 - 04:09 AM
noor.mz143, on 7 Feb, 2007 - 01:11 AM, said:
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.
#4
Re: Print number in reverse order
Posted 25 June 2008 - 03:03 PM
#5
Re: Print number in reverse order
Posted 25 September 2008 - 08:26 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 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
#6
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*/
Please try this.
#7
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!!!
This post has been edited by JackOfAllTrades: 05 November 2010 - 04:05 AM
#8
Re: Print number in reverse order
Posted 05 November 2010 - 03:02 AM
Should we lock this one down because it seems it will never die otherwise?
#10
Re: Print number in reverse order
Posted 05 November 2010 - 04:06 AM
|
|

New Topic/Question
This topic is locked




MultiQuote








|