sine series

Discussion in 'Programmer's Corner' started by swty_todd, Jan 29, 2009.

  1. swty_todd

    Thread Starter Active Member

    Aug 3, 2008
    82
    0
    i m unable 2 get the output for the followin c program.
    The factorial program is correct
    i think there is problem in the FOR loop..guess its goin infinite...pls help
    #include<stdio.h>
    #include<math.h>
    factorial(int);
    main()
    {
    int n,count,i;
    float number,x,series;
    printf("nter number and no of terms");
    scanf("%f %d",&number,&n);
    x=3.14*number/180;
    count=0;
    series=0;
    for(i=1;i<=(2*n);i+2)
    {
    series=series+pow(x,i)*pow(-1,count)/factorial(i);
    count=count++;
    }
    printf("%f",series);
    return 0;
    }
    int factorial(int m)
    {int fact;
    if(m==1)
    return (1);
    else
    fact=m*factorial(m-1);
    return(fact);
    }
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    See if the change I have made in the line shown in red gets things going.

    hgmjr
     
  3. swty_todd

    Thread Starter Active Member

    Aug 3, 2008
    82
    0
    its workin nw...thnx 4 ur help>>>
     
Loading...