Swap digits of a number


Submit solution

Points: 20 (partial)
Time limit: 8.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
C

Write a C program that accepts a number as input, swaps the first and last digit of the number and prints it.

Sample inputs

123

67834

Sample outputs

321

47836


Comments


  • 0
    EEE22061  commented on May 4, 2023, 4:19 p.m.

    include<stdio.h>

    include<math.h>

    int main() { int a,d,n,di,newnum; int p; scanf("%d",&n); p=(int)log10(n); d=n%10; di=pow(10,p); a=n/di; newnum=d*di+n%(di)+a-d; printf("\n%d",newnum); }