Click here to Skip to main content
15,910,009 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
This is the problem:
1098 - Sequence IJ 4 - beecrowd[^]

What I have tried:

#include<stdio.h>
int main(){
double i,j;


for(i=0; i<=2; i=i+0.2){
    for(j=1; j<=3; j++){

        if (i==0){
            printf("%.0lf %.0lf\n", i, j+i);
        }else if(i==1){
        printf("%.0lf %.0lf\n", i, j+i);
        }else if(i==2){
        printf("%.0lf %.0lf\n", i, j+i);
        }else{
        printf("%.1lf %.1lf\n", i, j+i);
        }
    }
}
return 0;
}
Posted
Updated 26-Oct-21 19:14pm

Here's the solution.
#include<stdio.h>

int main(){
double i,j;


for(i=0; i<=2; i=i+0.2){
    for(j=1; j<=3; j++){

        if (i<0.1){
            printf("I=%.0lf J=%.0lf\n", i, j+i);
        }else if(i>0.9&&i<1.1){
        printf("I=%.0lf J=%.0lf\n", i, j+i);
        }else if(i>1.8&&i<2.1){
        printf("I=%.0lf J=%.0lf\n", i, j+i);
        }else{
        printf("I=%.1lf J=%.1lf\n", i, j+i);
        }
    }
}
return 0;
}
 
Share this answer
 
Comments
Rick York 27-Oct-21 17:27pm    
That might work but it has serious limitations. I have revised my solution to show you what it should be more like.
The answer is the same as the last time you asked the question : 'Else if' is not working[^]

Using the CloseEnough function from before, here is how this could look :
C++
int main()
{
    double i,j;

    for( i=0; i<=2; i += 0.2 )
    {
        for( j=1; j <= 3; ++j )
        {
            if( CloseEnough( i, 0 ) )
            {
                printf("%3.1f %3.1f\n", i, j+i);
            }
            else if( CloseEnough( i, 1 ) )
            {
                printf("%3.1f %3.1f\n", i, j+i);
            }
            else
            {
                printf("%3.1f %3.1f\n", i, j+i);
            }
        }
    }
    return 0;
}
 
Share this answer
 
v2
Comments
Jahirul Sarker 26-Oct-21 22:48pm    
Please help me to solve it... I'am trying it for almost ten days.
Jahirul Sarker 26-Oct-21 22:51pm    
Your answer for this problem is good.. But I can't figure out the solution. I am new to programming... please help.. I am exhausted.
Jahirul Sarker 28-Oct-21 7:27am    
"Undefined reference to 'closeEnough'"
"error: Id returned 1 exit status."
IDE is showing this message. I use CodeBlocks 20.03.
I added stdio library, stdlib lib, math lib... But Program doesn't run.
by adding .2 to i you are never going to match your if statements, it will always default to the last else statement.
 
Share this answer
 
Comments
Jahirul Sarker 26-Oct-21 23:09pm    
What should I do?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900