File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import java .util .Scanner ;
22
3- class krishnamurthy
4- {
5- int fact (int n )
6- {
7- int i ,p =1 ;
8- for (i =n ;i >=1 ;i --)
9- p =p *i ;
10- return p ;
11- }
12- public static void main (String args [])
13- {
14- Scanner sc =new Scanner (System .in );
15- int a ,b ,s =0 ;
16- System .out .print ("Enter the number : " );
17- a =sc .nextInt ();
18- int n =a ;
19- while (a >0 )
20- {
21- b =a %10 ;
22- s =s +fact (b );
23- a =a /10 ;
24- }
25- if (s ==n )
26- System .out .print (n +" is a krishnamurthy number" );
27- else
28- System .out .print (n +" is not a krishnamurthy number" );
29- }
3+ class krishnamurthy {
4+ static int fact (int n ) {
5+ int i , p = 1 ;
6+ for (i = n ; i >= 1 ; i --)
7+ p = p * i ;
8+ return p ;
9+ }
10+
11+ public static void main (String args []) {
12+ Scanner sc = new Scanner (System .in );
13+ int a , b , s = 0 ;
14+ System .out .print ("Enter the number : " );
15+ a = sc .nextInt ();
16+ int n = a ;
17+ while (a > 0 ) {
18+ b = a % 10 ;
19+ s = s + fact (b );
20+ a = a / 10 ;
21+ }
22+ if (s == n )
23+ System .out .print (n + " is a krishnamurthy number" );
24+ else
25+ System .out .print (n + " is not a krishnamurthy number" );
26+ sc .close ();
27+ }
3028}
You can’t perform that action at this time.
0 commit comments