diff options
author | smlckz <smlckz@college> | 2021-12-24 15:21:53 +0530 |
---|---|---|
committer | smlckz <smlckz@college> | 2021-12-24 15:21:53 +0530 |
commit | 6dec141d4529a490384eb42314c04428fc58ba20 (patch) | |
tree | a0bc436963bfa404c5208f12ad637f11fc70b20d /assignments/25-krishnamurti.c | |
parent | b73983c3717642ca10e7cfe93d97609adc377da9 (diff) | |
download | college-master.tar.gz |
Diffstat (limited to 'assignments/25-krishnamurti.c')
-rw-r--r-- | assignments/25-krishnamurti.c | 53 |
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. + +*/ + |