Math Functions (Using COSINE Function)

Write a program to show the use of Math Functions.

Hints: We often use standard mathematical functions such as cos,sin,exp,etc. We shall see now the use of a mathematical function in a program. The standard mathematical functions are defined and kept as a part of C math library.

#include<math.h>
#define PI       3.1416
#define MAX       180
main()
{
 int angle;
 float x,y;
 angle = 0;
 printf("        Angle        Cos(angle)\n\n");

 while (angle <= MAX)
 {
   x = (PI / MAX) * angle;
   y = cos(x);
   printf("%15d  %13.4f\n", angle,y);
   angle = angle + 10;
  }
}


Output:

        Angle        Cos(angle)
               0         1.0000
              10         0.9848
              20         0.9397
              --            ----
              --            ----
              180       -1.0000

Comments

  1. #include
    #define PI 3.1416
    #define MAX 180
    main()
    {
    int angle;
    float x,y;
    printf("Enter the angle:\n");
    while (scanf("%d",&angle)==1)
    {
    x = (PI / MAX) * angle;
    y = cos(x);
    printf(" The angle is: %d\n The value is: %f\n", angle,y);
    if(angle>=180)
    {
    break;
    }
    }
    }

    ReplyDelete
  2. #include
    #include
    #define pi 3.1416
    #define MAX 180
    void main()
    {
    int angel;
    float a=0.0,b=0.0;
    printf("Enter the value of Angel: ");
    scanf("%d",&angel);
    if(angel<=MAX)
    {
    a=(pi/MAX)*angel;
    b=cos(a);
    printf("The vaule of %d is: %0.4f",angel,b);
    }
    //printf("The vaule of %d is: %f",angel,b);
    }

    ReplyDelete
  3. #include
    #include

    int main()
    {
    double b,c;
    b = 40;
    c = sqrt(b);
    printf("%f",c);

    return 0;
    }

    ReplyDelete
  4. Uzzal HossenAugust 26, 2014 at 12:20 AM

    #include
    #include

    int main()
    {
    double b,c;
    b = 40;
    c = sqrt(b);
    printf("%f",c);

    return 0;
    }

    ReplyDelete
  5. #include
    #include
    #define PI 3.1416
    #define MAX 180
    void main()
    {
    int i=3,angel;
    float all=0.0,b=0.0;
    for(angel=0;angel<=MAX;angel++)
    {
    if(angel=i)
    {
    all=(PI/MAX)*angel;
    b=cos(all);
    printf("The vaule of %d is: %0.4f",angel,b);
    break;
    }
    }
    }

    ReplyDelete

Post a Comment