taylor series using only stdio.h

This is a discussion on taylor series using only stdio.h within the C Programming forums, part of the General Programming Boards category; guys. check this code. can you please make it compact? i mean i am not allowed to use any function ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    1

    taylor series using only stdio.h

    guys. check this code. can you please make it compact?
    i mean i am not allowed to use any function but main. i need help.
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #define PI 3.141592653589
    #define NUMBER_OF_TERMS 10
    
    
    double factorial(double x)
    {
          double ctr, total;
          ctr=x;
          total=x;
          while(ctr>1)
          {
             ctr--;
             total = total * ctr;
          }
          return total;
    }
    double power(double x, double y)
    {
          double ctr, z;
          ctr=0;
          z = x;
          while (ctr<(y-1))
          {
                ctr++;
                x = x * z;
          }
          return x;
    }
    double cosine_func(double radians)
    {
          int ctr, x;
          double cosine;
          x=0;
          ctr=0;
          cosine = 0;
          while(ctr<NUMBER_OF_TERMS-1)
          {
                     ctr++;
                     x=x+2;
                     if(ctr%2 == 0)
                      {
                          cosine = cosine - (power(radians, x)/factorial(x));
                      }
                     else if(ctr%2 != 0)
                     {
                          cosine = cosine + (power(radians, x)/factorial(x));
                     }
                     
          }
          return cosine;
    }
    main()
    {
          double ctr;       // counter
          double x;         // x value
          double radians;   // value of x in radians
          double cosine;    // cosine of x
          double cosinetest;// cosine of x
          double sine;      // sine of x
          
          printf("AGUSTIN_MARK S27\n\n");
          printf("x(degrees)\t   x(radians)\t\t     cos x\t\tsin x\n");
          ctr = 0;
          x = -185;
          while (x<180)
          {
                ctr++;
                x+=5;
                radians=x*PI/180.0;
                cosine=1-cosine_func(radians);
                sine=0;
                printf("%.2lf\t\t%.12lf\t\t%.12lf\t\t%.2lf\n", x, radians, cosine, sine);
          }
          system("pause");
    }

  2. #2
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    guys. check this code. can you please make it compact?
    i mean i am not allowed to use any function but main. i need help.
    Why not create your own thread ?

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Oh my goodness!!!!! I think this is called bumping a thread. After 6 years.................
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    Registered User
    Join Date
    Jun 2009
    Location
    US of A
    Posts
    305

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    Split from dead thread
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stdio.h cstdio.h
    By salvadoravi in forum C Programming
    Replies: 3
    Last Post: 01-21-2008, 02:00 PM
  2. error: stdio.h: No such file or directory
    By MindLess in forum C Programming
    Replies: 9
    Last Post: 12-20-2007, 07:11 AM
  3. stdio.h
    By Vertex34 in forum C Programming
    Replies: 2
    Last Post: 07-12-2004, 10:18 AM
  4. error in -stdio.h __VALIST
    By JaWiB in forum C++ Programming
    Replies: 3
    Last Post: 09-20-2003, 12:22 PM
  5. Modifying stdio.h
    By Spectrum48k in forum C Programming
    Replies: 10
    Last Post: 05-29-2002, 08:30 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21