We need to remove a piece of number in each line.



  • There's 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;
    }

    That's what's on the screen. 1.000000 In every line, I don't know how to do it. Help me.



  • 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 &lt; a + 100, j &lt; b + 100; i++, j++)
    {
        ostringstream out;
        out.precision(9);
        out &lt;&lt; (double) i / j;
        cout &lt;&lt; out.str().substr(6) &lt;&lt; endl;
        k++;
    }
    system("pause");
    return 0;
    

    }


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2