From 6dec141d4529a490384eb42314c04428fc58ba20 Mon Sep 17 00:00:00 2001 From: smlckz Date: Fri, 24 Dec 2021 15:21:53 +0530 Subject: backup --- assignments/25-krishnamurti.c | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 assignments/25-krishnamurti.c (limited to 'assignments/25-krishnamurti.c') 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 + +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. + +*/ + -- cgit 1.4.1-2-gfad0