TOPIC

Wrong Answer 5% don't know Why. Please help me.

Qu33n asked 1 year ago

include

void main() { double i; double j; for(i=0.0;i<=2;i=i+0.2) { for(j = 1.0;j<=3;j = j+1.0) { if(i==0 || i== 1 || i > 1.8) printf("I=%.0lf J=%.0lf\n",i,j); else if(i>=1) printf("I=%.1lf J=%0.1lf\n",i,j+i-1); else printf("I=%.1lf J=%0.1lf\n",i,j+i); } } }

Remember not post solutions. Your post may be reviewed by our moderators.

  • mefahimrahman replied 8 months ago

    Your 5% error occurs because your code outputs ->

    **I=1 j=1 I=1 j=2 I=1 j=3

    I=2 j=1 I=2 j=2 I=2 j=3**

    But actual output should be ->

    ** I=1 j=2 I=1 j=3 I=1 j=4

    I=2 j=3 I=3 j=4 I=4 j=5**

    My Code ->

    #include<bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        for(double i=0; i<=2; i+=0.2)
            for(double j=1; j<=3; j++)
                cout<<"I="<<i<<" "<<"J="<<j+i<<endl;
    }