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
I=0 J=2 I=0 J=3 I=0.2 J=1.2 I=0.2 J=2.2 I=0.2 J=3.2 ..... I=2 J=? I=2 J=? I=2 J=? |
Solution using C :
#include <stdio.h>
int main() {
int p=0;
float i=0.0,j;
for(i=0.0; i<2.2; i=i+0.2)
{
if(p==5) p=0;
for(j=1; j<=3; j++)
{
if(p==0)
printf("I=%.0f J=%.0f\n",i,j+i);
else if(i==2.0)
printf("I=%.0f J=%.0f\n",i,j+i);
else
printf("I=%.1f J=%.1f\n",i,j+i);
}
p++;
}
return 0;
}
for i in range(0, 21, 2):
ReplyDeletek = i / 10.0
for j in range(1, 4, 1):
if k == 0:
print("I={:.0f} J={:.0f}".format(k, j))
elif k == 2.0 or k == 1.0:
print("I={:.0f} J={:.0f}".format(k, j + k))
else:
print("I={:.1f} J={:.1f}".format(k, j + k))