Interchange the last two digits of an inputted number


C program to interchange the last two digits of an inputted number.

Sample input:
12369

Output:
12396

Program:

#include<stdio.h>
int main()
{
         int num,temp1,temp2;
         printf("enter num: ");
         scanf("%d",&num);
         temp1=num%10;
         temp2=num/10;
         temp2=temp2%10;
         num=num-(10*temp2)+(10*temp1)-(temp1)+(temp2);
         printf("%d",num);
         return 0;
}
 

No comments: