New Android apps UniqueKey

Saturday 7 March 2015

Computing equation using recursive function.


/*a c program to compute equation using a recursive function*/

#include<stdio.h>
#include<math.h>

long int power(int,int);               //declaration of function

main()
{
  int num,x;
  long int sum;
  
  printf("---------------------------------\n");

  printf("your equation is::\n");
  printf("4*x^5+3*x^4+2*x^3+x^2+x\n");      //to show the equation

  printf("--------------------------------\n");

  printf("enter the value of x\n");         //to enter the value of x
  scanf("%d",&x);   

  sum=4*power(x,5)+3*power(x,4)+2*power(x,3)+power(x,2)+x;         // using the function

  printf("-------------------------------\n");

  printf("result of given equation is :: %ld\n",sum);

  printf("--------------------------------\n");
}

long int power(int num1,int num2)          //definition of the function
{
  if(num2!=1)
  return(num1*power(num1,num2-1));      
}

No comments:

Post a Comment