Sunteți pe pagina 1din 1

Solution to Problem Set 4 Question No.

2(i) :

Program:

/* Program to calculate a real root of the equation 3*x - cosx - 1 = 0 using iteration method */

#include<stdio.h>
#include<math.h>

void main()
{
int i;
float x1,x2;
float f(float a);

clrscr();

printf("\nEnter the initial value of the root : ");


scanf("%f",&x1);
x2=f(x1);

while(fabs(x1-x2) > 0.00001)


{
x1=x2;
x2=f(x1);
}

printf("The value of the root is : %f",x2);


getch();
}

float f ( float a)
{
return ( 1 + cos (a))/3;
}

S-ar putea să vă placă și