Easy Programming All

Easy Programming All

Monday, December 17, 2018

WAP in C to check Whether a given Number is Krishnamurthi or Not

#include<stdio.h>
int main()
{
int i, n, fact, sum = 0, copy, rem;
printf("Enter any positive integer number to check Krishnamurthi or Not\n");
scanf("%d",&n);
copy = n;
while(n > 0)
{
rem = n % 10;
fact = 1;
for(i = 1; i <= rem; i++)
fact = fact * i;
sum = sum + fact;
n = n / 10;
}
if(copy = = sum)
{
printf("%d given Number is Krishnamurthi",copy);
}
else
{
printf("%d  Number is Not Krishnamurthi",copy);
}
return 0;
}


INPUT 1:
Enter any positive integer number to check Krishnamurthi or Not
145
OUTPUT 1:
145  Number is Krishnamurthi

INPUT 2:
Enter any positive integer number to check Krishnamurthi or Not
123
OUTPUT 2:
123  Number is Not Krishnamurthi





No comments:

Post a Comment