Thread: C programming basics

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    21

    C programming basics

    I wrote code for sinx

    But it is showing output as INF

    Why INF?? what's wrong with code ....
    plz help


    Code:
    #include<stdio.h>
    #include<math.h>
    int main()
    {
    float x,t=0,sum;
    int i,n,sig=1;
    printf("Input X,N");
    scanf("%f %d",&x,&n);
    x*=(3.14/180);
    sum=x;
    for(i=0;i<n;i++)
    {
    sig*=-1;
    t=(sig*x*x)/(2*i*(2*i+1));
    sum+=t;
    }
    printf("SIN(X) = %f\n",sum);
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2012
    Posts
    357
    The first time throught the loop, i is zero ... and the calculation for t implies a division by zero, which yields INFINITY

    Code:
    t=(sig*x*x)/(2*i*(2*i+1)); // divide by zero

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    21
    Quote Originally Posted by qny View Post
    The first time throught the loop, i is zero ... and the calculation for t implies a division by zero, which yields INFINITY

    Code:
    t=(sig*x*x)/(2*i*(2*i+1)); // divide by zero
    Thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Programming basics
    By raghu_c in forum C Programming
    Replies: 2
    Last Post: 06-03-2010, 07:53 PM
  2. Pointers basics (C and other Programming Lamguages)
    By neilsequeira in forum C Programming
    Replies: 5
    Last Post: 08-19-2007, 03:21 PM
  3. Game Programming Basics?
    By Dark Dude in forum Game Programming
    Replies: 15
    Last Post: 10-01-2006, 03:36 AM
  4. Basics of C/C++ game programming
    By XvXJTNWXvX in forum Game Programming
    Replies: 14
    Last Post: 10-25-2003, 12:18 PM
  5. What are the Basics of packet programming?
    By PsychoMantis in forum C++ Programming
    Replies: 4
    Last Post: 07-25-2002, 07:02 PM
Website Security Test