Click here to Skip to main content
13,665,440 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
You are given a positive integer N. You have to reverse the digits of
N. Let us denote this number by R. You must output N+R.

Input
-----
A positive integer.

Output
------
The sum of the integer and the reverse of the integer.

Sample Input 1
--------------
547

Sample Output 1
---------------
1292

Explanation
-----------
The reverse of 547 is 745. The sum of 547 and 745 is 1292.

What I have tried:

plzz answer it fast as possible
Posted 16-Sep-17 22:55pm
Updated 4 days ago
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Quote:
plzz answer it fast as possible
It doesn't work that way. You have to try harder to solve the problem and ask here specific questions whenever you are stuck.

Hint: the rightmost (less significant) digit of the decimal number N is (N%10).

(As an alternative you could convert the number to a string, reverse the string and convert it back to a number).
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

We do not write code for you and your homework, this forum is for people who have genuine problems not people who are lazy and can't be bothered to even try.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

#include<stdio.h>
void main()
{
int n,r,s,rm,n1;
scanf("%d",&n);
n1=n;
s=0;
while(n>0)
{
rm=n%10;
s=s*10+rm;
n=n/10;
}
printf("%d",s+n1);
}
  Permalink  
Comments
ppolymorphe 17-Sep-17 5:39am
   
Just giving a full blowup solution to homework is defeating its purpose and prevent learning.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

#include<stdio.h>
void main()
{
int n,a,r,s=0;
printf("enter number:");
scanf("%d",&n);
a=n;
while(n) //executes until n!=0
{
r=n%10;
s=s*10+r;
n/=10;
}
printf("\nsum is %d:",a+s);
}
  Permalink  
v2
Comments
Dave Kreskowiak 11-Jul-18 15:51pm
   
Doing some's homework for them is frowned up around here. I suggest you don't do it again.

Oh, and you're only a year late. I seriously doubt the OP is still waiting for someone to do his/her work for them.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

#include <stdio.h>

int main()
{
int n,t,r=0,t1,sum;
printf("enter the number between 1 to 999\t");
scanf("%d",&n);
if(n<1||n>999)
{
printf("invalid input");
}
else{
printf(" number is %d\t",n);
t=n;
while(t>0)
{ t1=t%10;
r=r*10+t1;
t=t/10;
}
printf(" \nreverse is %d",r);
sum=n+r;
printf("\naddition is %d",sum);
}
}
  Permalink  
Comments
CHill60 27-Jul-18 5:57am
   
Did you not read the other solutions and the comments?
"Just giving a full blowup solution to homework is defeating its purpose and prevent learning."
"Doing some's homework for them is frowned up around here. I suggest you don't do it again."
"Oh, and you're only a year late. I seriously doubt the OP is still waiting for someone to do his/her work for them."
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 7

#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,sum=0,rev=0;
scanf("%d",&n);
while(n!=0)
{
r=n%10;
sum=sum+r;
rev=rev*10+r;
n=n/10;
}
printf("%d%d",sum,rev);
getch();
}
  Permalink  
v3
Comments
ppolymorphe 31-Jul-18 11:29am
   
1 year too late and the code is wrong !
If you want to help, try to focus on actual questions.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 8

#include<stdio.h>
int main()
{
int n,rev=0,sum=0,temp,rem;
printf("enter the number n\n");
scanf("%d",&n);
temp=n;
while(n>0)
rem=n%10;
rev=rev*10+rem;
n=n/10;
printf("reverse number=%d\n",rev);
sum=temp+rev;
printf("Sum=%d\n",sum);
return 0;
}
  Permalink  
v3
Comments
Dave Kreskowiak 12-Aug-18 21:00pm
   
FFS. Read the other answers and comments on them.

This question is over a year old and it was to have someone do their homework for them. THAT DOES NOT HELP THE PERSON DEMANDING THE CODE.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 9

#include<stdio.h>
void main(){
int n,y,sum=0;
printf("\n enter any positive integer:");
scanf("%d",&n);
y=n;
while(n!=0){
sum=(sum*10)+(n%10);
n=n/10;
}
printf("sum of %d and %d is %d",y,sum,sum+y);
}
  Permalink  
v3
Comments
CHill60 13-Aug-18 3:58am
   
Read the comments to the other posts!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180810.1 | Last Updated 14 Aug 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100