diff --git a/Week1/q1.c b/Week1/q1.c new file mode 100644 index 0000000..1f12790 --- /dev/null +++ b/Week1/q1.c @@ -0,0 +1,32 @@ +#include + +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); +}