There is a code:

#include <iostream> #include <cmath> using namespace std; int main() { int a, b, k; a = 67865; b = 67864; cout.precision(8); for (int i = a, j = b; i < a + 100, j < b + 100; i++, j++) { cout << fixed << (double) i / j << endl; k++; } system("pause"); return 0; } 

In the fact that it was displayed on the screen you need to remove 1.0000 on each line, I don’t know how to do this .. Help (The numbers should be 4 digits)

  • Explain exactly what you want to get. Numbers in the range 1473-1471 , or what? Then simply subtract one from the i / j result and multiply it by 100,000,000. Drop the fractional part ( cout.precision(0) ?) And get what you want. But what does C ++ do with it, this is arithmetic for elementary school. Or maybe something I did not understand? - PinkTux pm
  • Well, you can somehow without divisions and multiplications, stupid at the beginning of each line to delete 6 characters? - Aru Akice pm
  • Try then not in int, but in string. - Artik Slayer
  • Excuse me, how?)) Can you show? - Aru Akice pm
  • Nothing is clear. Write what is realistically displayed and what you would like to receive. - VladD

1 answer 1

As an option

 #include <iostream> #include <cmath> #include <sstream> using namespace std; int main() { int a, b, k; a = 67865; b = 67864; for (int i = a, j = b; i < a + 100, j < b + 100; i++, j++) { ostringstream out; out.precision(9); out << (double) i / j; cout << out.str().substr(6) << endl; k++; } system("pause"); return 0; } 
  • Yes! This is what I needed! - Aru Akice