Write a program using math funtion.

We often use standard mathematical funtions such as cos, sin, exp, etc. In this program we add a new header called #include"math.h" that instructs the compiler to link the specified mathematical function form the library. We shall see now the use of a mathematical function in a program.

#include <stdio.h>
#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
30 0.8660
40 0.7660
.
.
.
.
.
160 -0.9397
170 -0.9848
180 -1.0000

0 comments:

Post a Comment

 

About Me

It's Me!Hi, I'm Moinuddin. I'm a Software Engineer at WIPRO working on Microsoft .NET Technology. I'm interested in a wide range of technology topics, mainly Microsoft including Windows Azure, WCF, WPF, Silverlight and any other cool technology that catches the eye.

Site Info

ProjectCSharp.com is mainly about demonstrating real time examples in different technologies like ASP.NET, WCF, WPF, Silverlight, Azure etc..,

Followers

Help Links

Project CSharp (C#) Copyright © 2011. All Rights Reserved.