1,105,232 Community Members

Program to swap 2 digit number

Member Avatar
dendenny01
Light Poster
46 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

As for my assignment I had to write a program to swap 2 digit number
Example:- If user input 12 the swaped number Would be 21.
Along with ALgorithm, and a short description on this program(As how will you solve this program or what measure you'll take to get desired results).
Please Help..

Member Avatar
mvmalderen
Nearly a Posting Maven
2,370 posts since Feb 2009
Reputation Points: 2,071 [?]
Q&As Helped to Solve: 282 [?]
Skill Endorsements: 40 [?]
 
0
 

Have you started already? If not, why so? What in particular are you having difficulties with?
As a hint: modulo 10, division by 10, multiplication by 10; you can pretty much solve your task using these operations.

Member Avatar
KaeLL
Newbie Poster
18 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

a piece of advice: try to work the digits separately.. and listen to the hint above!

Member Avatar
dendenny01
Light Poster
46 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Is this correct...

#include<stdio.h>
#include<conio.h>
void main();
{
int a,b,c;
printf("Enter a 2 digit number\n");
scanf("%d",&a);
b=a/10;
c=a%10;
printf("The swaped digits are %d%d",b,c);
getch();
}
Member Avatar
mvmalderen
Nearly a Posting Maven
2,370 posts since Feb 2009
Reputation Points: 2,071 [?]
Q&As Helped to Solve: 282 [?]
Skill Endorsements: 40 [?]
 
0
 

Is this correct...

Apart from not following the standard and being unportable I'd say no.
Did you even try it out? Compile, run and answer your own question.
If it doesn't compile, fix the compiler error, if it runs but doesn't produce the correct output, fix the bug and compile again.

Question Answered as of 1 Year Ago by mvmalderen and KaeLL
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: