SHARE
TWEET

Untitled

a guest Jul 18th, 2019 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Factorial {
  2.     int sum(int n)
  3.     {
  4.         int sm=0;
  5.         if(n==1)
  6.             return 1;
  7.         System.out.println("sm"+sm+"n"+n);
  8.         sm=n+sum(n-1);
  9.         System.out.println("sm"+sm);
  10.         return sm;
  11.     }
  12. public static void main(String[] args){
  13.     int n,s;
  14.    System.out.println("Enter the limit:");
  15.     n=3;
  16.     s=new Factorial().sum(n);
  17.     System.out.println("Sum of natural numbers %d"+s);
  18.     //return 0;
  19. }
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top