1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

pls tell me solution for correct output

Discussion in 'C' started by vipul15singh, Feb 26, 2010.

  1. vipul15singh

    vipul15singh New Member

    Joined:
    Feb 22, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    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);
    }
     
    Last edited by a moderator: Feb 27, 2010
  2. Fatima Khan

    Fatima Khan New Member

    Joined:
    Feb 20, 2010
    Messages:
    27
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pakistan
    vipul first of all tell me that whats wrong with it. is there any run time error or compiling error.
     
  3. Abinila

    Abinila New Member

    Joined:
    Feb 20, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Tell me what is problem in your code. Whether I need to change your algorithm?
     
  4. vipul15singh

    vipul15singh New Member

    Joined:
    Feb 22, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  5. vipul15singh

    vipul15singh New Member

    Joined:
    Feb 22, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  6. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    give us the mathematics solution for this.

    what equation do you use?
     
    shabbir likes this.
  7. vipul15singh

    vipul15singh New Member

    Joined:
    Feb 22, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    hi virxen, thanks
    it is also my thread for same problem.
    may u pls tell me a good way for quicksort.
     
  8. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0

Share This Page