Programming Examples

C program to check number is Krishnamurti number or not


Write a program to print all the Krishnamurti number from 1 to n. Here, n is user dependent. A Krishnamurti number is a number whose sum of factorial of individual digits equals the number.

For example, 145 = 1! + 4! + 5! = 1 + 24+ 120 = 145.

Solution

#include<stdio.h>
int factorial(int);
int main()
{
	int num,digit,sum=0,temp;
	printf("Enter any Number : ");
	scanf("%d",&num);
	temp=num;
	while(num>0)
	{
		digit=num%10;
		sum=sum+factorial(digit);
		num=num/10;
	}
	if(sum==temp)
	{
		printf("Number is a Krishnamurti Number");
	}
	else
	{
		printf("Number is Not a Krishnamurti Number");
	}
	return 0;
}
int factorial(int num)
{
	int fact=1;
	while(num>=1)
	{
		fact=fact*num;
		num--;
	}
	return (fact);
}
Output

Enter any Number : 145

Number is a Krishnamurti Number


Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad