Eat - Code - Sleep - Repeat
osthir
By JAVA int test; Scanner sc=new Scanner(System.in); test=sc.nextInt(); int j; for(j=1;j<=test;j++) { int first,sec,i,counta=0; first=sc.nextInt(); sec=sc.nextInt(); if(first==sec) { counta=0; } else if(first<sec) { if(first%2!=0) { for(i=first+2;i<sec;i=i+2) { counta=counta+i; } } else{ for(i=first+1;i<sec;i=i+2) { counta=counta+i; } } } else { if(sec%2!=0) { for(i=sec+2;i<first;i=i+2) { counta=counta+i; } } else{ for(i=sec+1;i<first;i=i+2) { counta=counta+i; } } } System.out.println(counta); }
osthir
ReplyDeleteBy JAVA
ReplyDeleteint test;
Scanner sc=new Scanner(System.in);
test=sc.nextInt();
int j;
for(j=1;j<=test;j++)
{
int first,sec,i,counta=0;
first=sc.nextInt();
sec=sc.nextInt();
if(first==sec)
{
counta=0;
}
else if(first<sec)
{
if(first%2!=0)
{
for(i=first+2;i<sec;i=i+2)
{
counta=counta+i;
}
}
else{
for(i=first+1;i<sec;i=i+2)
{
counta=counta+i;
}
}
}
else
{
if(sec%2!=0)
{
for(i=sec+2;i<first;i=i+2)
{
counta=counta+i;
}
}
else{
for(i=sec+1;i<first;i=i+2)
{
counta=counta+i;
}
}
}
System.out.println(counta);
}