Algorithm
Sequence IJ 4
Adapted by Neilor Tonin, URI Brazil
Make a program that prints the sequence like the following example.
Input
This problem doesn't have input.
Output
Print the sequence like the example below.
Input Sample | Output Sample |
I=0 J=1 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main(){
float i = 0;
float j = 1;
while(i < = 2.2){
if((i>0 && i<1>|| (i>1 && i<2) || (i>2.1 && i<=2.2) )
{
printf("I=%0.1f J=%0.1f\n",i,j+i);
printf("I=%0.1f J=%0.1f\n",i,j+1+i);
printf("I=%0.1f J=%0.1f\n",i,j+2+i);
}
else
{
printf("I=%d J=%d\n",(int)i,(int)j+(int)i);
printf("I=%d J=%d\n",(int)i,(int)j+1+(int)i);
printf("I=%d J=%d\n",(int)i,(int)j+2+(int)i);
}
i+= 0.2;
}
return 0;
}
Copy The Code &
Try With Live Editor
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
using namespace std;
int main(){
float i = 0;
float j = 1;
while(i < = 2.1){
cout << "I=" << i << " " << "J=" << j+i << "\n";
cout << "I=" << i << " " << "J=" << j+1+i << "\n";
cout << "I=" << i << " " << "J=" << j+2+i << "\n";
i+= 0.2;
}
return 0;
}
Copy The Code &
Try With Live Editor
Output
#3 Code Example with Python Programming
Code -
Python Programming
i = 0
j = 1
value = 0
temp = 0
temp2 = 0
while (i <= 2):
if (temp2 == 0):
print("I=%.0f J=%.0f" % (i, j))
else:
print("I=%.1f J=%.1f" % (i, j))
temp += 1
if (temp == 3):
i += 0.2
value += 0.2
j = value
temp = 0
temp2 += 1
if(temp2 == 5):
temp2 = 0
j += 1
Copy The Code &
Try With Live Editor
Output