summary refs log tree commit diff stats
path: root/assignments/06-check-palindrome-number.c
diff options
context:
space:
mode:
authorsmlckz <smlckz@college>2021-12-22 14:56:13 +0530
committersmlckz <smlckz@college>2021-12-22 14:56:13 +0530
commitb73983c3717642ca10e7cfe93d97609adc377da9 (patch)
treea6e9fe4c27e3caa215f8aefa9265fb52f6de4375 /assignments/06-check-palindrome-number.c
downloadcollege-b73983c3717642ca10e7cfe93d97609adc377da9.tar.gz
backup
Diffstat (limited to 'assignments/06-check-palindrome-number.c')
-rw-r--r--assignments/06-check-palindrome-number.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/assignments/06-check-palindrome-number.c b/assignments/06-check-palindrome-number.c
new file mode 100644
index 0000000..d1a10d8
--- /dev/null
+++ b/assignments/06-check-palindrome-number.c
@@ -0,0 +1,47 @@
+/* Check whether a given number is palindromic or not */
+
+#include <stdio.h>
+
+int main(void)
+{
+	int n, m, p, r;
+	printf("Check whether a given number is palindromic\n\n");
+	printf("Enter a number: ");
+	scanf("%d", &n);
+	m = n;
+	p = 0;
+	while (m > 0) {
+		r = m % 10;
+		m = m / 10;
+		p = p * 10 + r;
+	}
+	if (p == n) {
+		printf("%d is a palindromic number.\n", n);
+	} else {
+		printf("%d is not a palindromic number.\n", n);
+	}
+	return 0;
+}
+
+/*
+Output:
+Set 1:
+Check whether a given number is palindromic
+
+Enter a number: 0
+0 is a palindromic number.
+
+Set 2:
+Check whether a given number is palindromic
+
+Enter a number: 123456
+123456 is not a palindromic number.
+
+Set 3:
+Check whether a given number is palindromic
+
+Enter a number: 1234321
+1234321 is a palindromic number.
+
+*/
+