Created
July 7, 2019 07:38
-
-
Save chaudharisuresh997/5bb489c88a4ba571a4e86b1317247c6d to your computer and use it in GitHub Desktop.
Factorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Factorial { | |
int sum(int n) | |
{ | |
int sm=0; | |
if(n==1) | |
return 1; | |
System.out.println("sm"+sm+"n"+n); | |
sm=n+sum(n-1); | |
System.out.println("sm"+sm); | |
return sm; | |
} | |
public static void main(String[] args){ | |
int n,s; | |
System.out.println("Enter the limit:"); | |
n=3; | |
s=new Factorial().sum(n); | |
System.out.println("Sum of natural numbers %d"+s); | |
//return 0; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment