Código:
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
double f(double x0,double y0)
{
double y;
//y=y0-2*x0/y0;
y=x0+y0;
return y;
}
void imp(double x0,double y0,double h,int N)
{
int n,flag;
double x1,y1,yp,yc;
n=1,flag=0;
cout<<"El resultado es:"<<endl;
cout<<" Xn Yn "<<endl;
do{
if(flag)
{
n+=1;
x0=x1;
y0=y1;
}
x1=x0+h;
yp=y0+h*f(x0,y0);
yc=y0+h*f(x1,yp);
y1=(yp+yc)/2;
printf(" %.1f %.4f\n",x1,y1);
flag=1;
}while(n!=N);
}
int main(int argc, char* argv[])
{
int N;
double x0,y0,h;
cout<<"Ingrese x0=";
cin>>x0;
cout<<"Ingrese y0=";
cin>>y0;
cout<<"Ingrese h=";
cin>>h;
cout<<"Ingrese N=";
cin>>N;
imp(x0,y0,h,N);
getch();
return 0;
}
No hay comentarios:
Publicar un comentario