"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Monday, January 11, 2010

Check Krishnamurti Number


// The sum of the factorial of each digit is equal to the number itself

#include<iostream.h>
#include<conio.h>

void main()
{
int a , j,sum = 0, dig, fact = 1;
cout<<"\n Enter a No.?";
cin>>a;

for(int i = a; i>0; i = i /10)
{
dig = i%10;
fact = 1;
j = 1;
while(j<=dig)
{
fact = fact * j;
j++;
}
sum = sum + fact;
}

if(sum == a)
cout<<"\n Krishna Murti No.";
else
cout<<"\n Not a Krishna Murti No.";

getch();
}


2 comments:

  1. JAVA One =

    import java.io.*;
    public class Krishnamurti
    {
    public static void main(String args[])Throws IOException
    {
    Buffer Reader br=new Buffer Reader (new Input Stream Reade(System.in)
    System.out.println("Enter A Number");
    int a=Integer.parsInt(br.readLine());
    int st1;
    int a1=a;
    while(a!=0)
    {
    st1=a%10;
    a=a/10;
    int st2=1;
    for(int i=1;i>=st1;i++)
    }
    }
    if(st2==a1)
    System.out.println("Your number is Krishnamurti");
    elce
    System.out.println("Your number is not Krishnamurti");
    }
    }
    (if you have any questione email me at duttaapd2009@gmail.com)

    ReplyDelete

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.