Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chaudharisuresh997/5bb489c88a4ba571a4e86b1317247c6d to your computer and use it in GitHub Desktop.
Save chaudharisuresh997/5bb489c88a4ba571a4e86b1317247c6d to your computer and use it in GitHub Desktop.
Factorial
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