diff options
author | smlckz <smlckz@college> | 2021-12-22 14:56:13 +0530 |
---|---|---|
committer | smlckz <smlckz@college> | 2021-12-22 14:56:13 +0530 |
commit | b73983c3717642ca10e7cfe93d97609adc377da9 (patch) | |
tree | a6e9fe4c27e3caa215f8aefa9265fb52f6de4375 /assignments/05-reverse-digits.c | |
download | college-b73983c3717642ca10e7cfe93d97609adc377da9.tar.gz |
backup
Diffstat (limited to 'assignments/05-reverse-digits.c')
-rw-r--r-- | assignments/05-reverse-digits.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/assignments/05-reverse-digits.c b/assignments/05-reverse-digits.c new file mode 100644 index 0000000..05fadd7 --- /dev/null +++ b/assignments/05-reverse-digits.c @@ -0,0 +1,43 @@ +/* Print the digits of given number in reverse order */ + +#include <stdio.h> + +int main(void) +{ + int n, m, r, sum, prod; + printf("Print the digits of given number in reverse order\n\n"); + printf("Enter a number: "); + scanf("%d", &n); + m = n; + printf("%d printed in reverse order is: ", n); + do { + r = m % 10; + m = m / 10; + printf("%d", r); + } while (m > 0); + printf("\n"); + return 0; +} + +/* +Output: +Set 1: +Print the digits of given number in reverse order + +Enter a number: 0 +0 printed in reverse order is: 0 + +Set 2: +Print the digits of given number in reverse order + +Enter a number: 123456 +123456 printed in reverse order is: 654321 + +Set 3: +Print the digits of given number in reverse order + +Enter a number: 541563249 +541563249 printed in reverse order is: 942365145 + +*/ + |