0% found this document useful (0 votes)
42 views1 page

C++ Iterative Calculation Code

This C++ program uses numerical integration to calculate the value of y for a given function f(x,y) at increasing values of x, starting from an initial x and y value provided by the user. The user inputs the step size h, initial x and y values, and final x value. The program then uses the Euler method in a while loop to calculate updated y values at each x+h interval from the initial point to the final x value, outputting the final calculated y.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views1 page

C++ Iterative Calculation Code

This C++ program uses numerical integration to calculate the value of y for a given function f(x,y) at increasing values of x, starting from an initial x and y value provided by the user. The user inputs the step size h, initial x and y values, and final x value. The program then uses the Euler method in a while loop to calculate updated y values at each x+h interval from the initial point to the final x value, outputting the final calculated y.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

main.

cpp 05/03/17, 11:27 PM

//programme by warrior MMB


//naam to suna hi hoga
#include<iostream>
#include<math.h>
using namespace std;
float f(float x, float y)
{
float y1=0;
y1=x+y;
return y1;
}
int main()
{
float y, x, h, n, y1;
cout<<"Enter the width of iteration:"<<endl;
cin>>h;
cout<<"Enter the initial X:"<<endl;
cin>>x;
cout<<"Enter the corresponding y value"<<endl;
cin>>y;
cout<<"Enter the final X:"<<endl;
cin>>n;
while( x<n)
{
y1=y+h*f(x,y);
y+=h/2*(f(x,y)+f(x+h,y1));
x=x+h;
}
cout<<"Y("<<x<<") :"<<y<<endl;
}

Page 1 of 1

You might also like