C program of Newton Raphson Method
#include
#include
#include
#include
int bigval,i=0,cnt=0,flag=0;
int coef[10]={0};
float x1=0,x2=0,t=0;
float fx1=0,fdx1=0;
int main()
{
printf("\n\n\t C PROGRAM FOR THE NEWTON RAPHSON METHOD");
printf("\n\n\n\t PLEASE ENTER THE MAXIMUM POWER OF X = ");
scanf("%d",&bigval);
for(i=0;i<=bigval;i++)
{
printf("\n\t x^%d = ",i);
scanf("%d",&coef[i]);
}
printf("\n");
printf("\n\t So, THE POLYNOMIAL IS "= ");
for(i=bigval;i>=0;i--)/*printing coefficients*/
{
printf(" %dx^%d",coef[i],i);
}
printf("\n\n\tFirst approximation x1 ----> ");
scanf("%f",&x1);
printf("\n ITERATION \t x1 \t F(x1) \t \tF'(x1) ");
do
{
cnt++;
fx1=fdx1=0;
for(i=bigval;i>=1;i--)
{
fx1+=coef[i] * (pow(x1,i)) ;
}
fx1+=coef[0];
for(i=bigval;i>=0;i--)
{
fdx1+=coef[i]* (i*pow(x1,(i-1)));
}
t=x2;
x2=(x1-(fx1/fdx1));
x1=x2;
printf("\n\t %d \t%.3f \t %.3f\t\t%.3f ",cnt,x2,fx1,fdx1);
}
while((fabs(t - x1))>=0.0001);
printf("\n\n\n\t AND.... THE ROOT OF EQUATION IS = %f",x2);
getch();
}
Related Links :
History Of C..
In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.
My 1st Program...
#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}
Next Step...
#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");
printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");
getch ();
}
No comments:
Post a Comment