From b73983c3717642ca10e7cfe93d97609adc377da9 Mon Sep 17 00:00:00 2001 From: smlckz Date: Wed, 22 Dec 2021 14:56:13 +0530 Subject: backup --- assignments/05-reverse-digits.c | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 assignments/05-reverse-digits.c (limited to 'assignments/05-reverse-digits.c') 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 + +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 + +*/ + -- cgit 1.4.1-2-gfad0