summary refs log tree commit diff stats
path: root/assignments/25-krishnamurti.c
diff options
context:
space:
mode:
authorsmlckz <smlckz@college>2021-12-24 15:21:53 +0530
committersmlckz <smlckz@college>2021-12-24 15:21:53 +0530
commit6dec141d4529a490384eb42314c04428fc58ba20 (patch)
treea0bc436963bfa404c5208f12ad637f11fc70b20d /assignments/25-krishnamurti.c
parentb73983c3717642ca10e7cfe93d97609adc377da9 (diff)
downloadcollege-master.tar.gz
backup HEAD master
Diffstat (limited to 'assignments/25-krishnamurti.c')
-rw-r--r--assignments/25-krishnamurti.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/assignments/25-krishnamurti.c b/assignments/25-krishnamurti.c
new file mode 100644
index 0000000..fd3a1ca
--- /dev/null
+++ b/assignments/25-krishnamurti.c
@@ -0,0 +1,53 @@
+#include <stdio.h>
+
+int fact(int n)
+{
+	int i, f = 1;
+	for (i = n; i > 1; i--) f *= i;
+	return f;
+}
+
+int is_krishnamurti(int n)
+{
+	int m = n, sum = 0, r;
+	while (m > 0) {
+		r = m % 10;
+		sum += fact(r);
+		m /= 10;
+	}
+	return n == sum;
+}
+
+int main(void)
+{
+	int n;
+	printf("To check whether a given number is a Krishnamurti number or not\n\n");
+	printf("Enter a number: ");
+	scanf("%d", &n);
+	printf("%d is%s a Krishnamurti number.\n", n, is_krishnamurti(n) ? "" : " not");
+	return 0;
+}
+
+
+/*
+Output:
+Set 1:
+To check whether a given number is a Krishnamurti number or not
+
+Enter a number: 2
+2 is a Krishnamurti number.
+
+Set 2:
+To check whether a given number is a Krishnamurti number or not
+
+Enter a number: 145
+145 is a Krishnamurti number.
+
+Set 3:
+To check whether a given number is a Krishnamurti number or not
+
+Enter a number: 123
+123 is not a Krishnamurti number.
+
+*/
+