Sunday, September 29, 2019

Recursive function --sum of series

1^1+2^2+3^3________+n^n
Recursion
Sum of series n to power n up to n terms



#include <stdio.h>
#include <stdlib.h>



npn(int x)
{ int i,r;

r=1;
for(i=1;i<=x;i++)
{  r=r*x;  }
return r;
}

sn(int n)
{ if(n==1)
return 1;
else{ return sn(n-1) +npn(n);}


}



main()
{ int b,k=1;
while(k==1)
{ system("cls");
printf("you are going to find sum series of n to power n,\nup to n terms \nenter no.of terms \n");
scanf("%d",&b);
printf("%d",sn(b));
printf("\n\n1.try once again\n2.exit\nchoose any option....");
scanf("%d",&k);
}

}

No comments:

Implement stsStr Leetcode solution

  28.   Implement strStr() Easy Implement  strStr() . Given two strings  needle  and  haystack , return the index of the first occurrence of...