Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   pls tell me solution for correct output (http://www.go4expert.com/forums/pls-tell-solution-correct-output-t21120/)

vipul15singh 26Feb2010 19:28

pls tell me solution for correct output
 
hi
here is a program for exponential but it desn,t work properly pls tell me the correction
Code:

#include<stdio.h>
#include<conio.h>
float expo(float,float,int,float);
float term(float,float,float);
main()
{
 int n;
 float e=0.0,t=1.0,x,s=1.0;
 clrscr();
 printf("\nenter variable & no ofterms:=");
 scanf("%f%d",&x,&n);
 e=expo(x,t,n,s);
 printf("\nsum=%f",e);
 getch();
 return;
}
float expo(float x,float t,int n,float s)
{
 float c=1.0,e=0;
 if(t<n)
 {
  e=term(x,t,c);
  s=s+e;
  expo(x,t+1.0,n,s);
 }
  return(s);
}
float term(float x,float t,float c)
{
 if(t>=1)
 {
  c=c*(x/t);
  term(x,t-1,c);
 }
  return(c);
}


Fatima Khan 26Feb2010 19:54

Re: pls tell me solution for correct output
 
vipul first of all tell me that whats wrong with it. is there any run time error or compiling error.

Abinila 27Feb2010 10:06

Re: pls tell me solution for correct output
 
Tell me what is problem in your code. Whether I need to change your algorithm?

vipul15singh 6Mar2010 17:32

Re: pls tell me solution for correct output
 
Quote:

Originally Posted by Fatima Khan (Post 64805)
vipul first of all tell me that whats wrong with it. is there any run time error or compiling error.

fatima, if you are intrested to solve this problem,pls copy the prog and run for x=1 and number of term n=5
the answer should be 2.7016

vipul15singh 6Mar2010 17:44

Re: pls tell me solution for correct output
 
Quote:

Originally Posted by Abinila (Post 64832)
Tell me what is problem in your code. Whether I need to change your algorithm?

hi abinila,i cant describe the problem but prob in recursion due to this, prog doesn,t able to calculate correct result. if u r really intrested to solve the problem run it for x=1 and n=5 the answer should be 2.7016

virxen 7Mar2010 21:24

Re: pls tell me solution for correct output
 
give us the mathematics solution for this.

what equation do you use?

vipul15singh 8Mar2010 00:38

Re: pls tell me solution for correct output
 
Quote:

Originally Posted by virxen (Post 65277)
give us the mathematics solution for this.

what equation do you use?

hi virxen, thanks
it is also my thread for same problem.
may u pls tell me a good way for quicksort.

virxen 8Mar2010 01:16

Re: pls tell me solution for correct output
 
quicksort
==============

http://alienryderflex.com/quicksort/

http://www.comp.dit.ie/rlawlor/Alg_D...ng/quickSort.c

http://cprogramminglanguage.net/quic...urce-code.aspx

http://www.daniweb.com/code/snippet216793.html#


All times are GMT +5.5. The time now is 10:16.