integral - C++ Integration Solution using Riemann Sum : Loses validity for greater than 10 partitions -


In an attempt to give a concise solution to an approximation of integral using the sum of Riemann, I ran into a strange problem Gone: If the user requested a partition number of more than 10, the program failed any idea? Here's the code:

  // Integral #include & lt; Algorithm & gt; # Include & lt; Iomanip & gt; # Include & lt; IOS & gt; # Include & lt; Iostream & gt; # Include & lt; Stdexcept & gt; # Include & lt; Iomanip & gt; Using std :: cin; Using std :: cout; Using the Std :: endl; Int func (int x); Int main () {cout & lt; & Lt; "Please enter the left and right border:"; Int left, right; Cin & gt; & Gt; Left & gt; & Gt; right; Cout & lt; & Lt; "Please enter # (& gt; 0) from the partitions:"; Int r; Cin & gt; & Gt; R; Int width = (right - left) / R; Integer = 0; For (int i = 0; i     

Using partition size greater than 10 is not your actual problem.

You are using an integer for your variable and function return value, when you should use float or double .

For example:

  width = (right - left) / r;  

If (right - left) & lt; The width will be zero!


Comments

Popular posts from this blog

php - multilevel menu with multilevel array -

c# - TypeConverter in propertygrid only converts from string, not to -

jQuery UI: Datepicker month format -