Week1 Assignment
This commit is contained in:
parent
46ffca0872
commit
3517cb4e8d
|
@ -0,0 +1,32 @@
|
||||||
|
#include<stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
// scan integer from input
|
||||||
|
int x;
|
||||||
|
scanf("%d", &x);
|
||||||
|
|
||||||
|
// Get the 5 digits, starting from 1s place
|
||||||
|
int ones = x %10;
|
||||||
|
|
||||||
|
x/=10;
|
||||||
|
int tens = x % 10;
|
||||||
|
|
||||||
|
x/=10;
|
||||||
|
int hundreds = x % 10;
|
||||||
|
|
||||||
|
x/=10;
|
||||||
|
int thousands = x % 10;
|
||||||
|
|
||||||
|
x/=10;
|
||||||
|
int tenthousands = x % 10;
|
||||||
|
|
||||||
|
// In reverse order, create the reversed number.
|
||||||
|
int reversed = tenthousands
|
||||||
|
+ 10*thousands
|
||||||
|
+ 100*hundreds
|
||||||
|
+ 1000*tens
|
||||||
|
+ 10000*ones;
|
||||||
|
|
||||||
|
// Output number.
|
||||||
|
printf("%d\n", reversed);
|
||||||
|
}
|
Loading…
Reference in New Issue