/*Before seeing the code solution make sure that you have tried enough. Don’t copy- paste the whole code. Find out the logic. If you face any trouble, just inform me in comment.*/
#include<stdio.h>
main()
{
int i,j,k,l=0,x,y,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
if(x>y)
{
for(j=y+1,l=0;j<x;j++)
{
if(j%2!=0)
{
l=l+j;
}
}
printf("%d\n",l);
}
else
{
for(j=x+1,l=0;j<y;j++)
{
if(j%2!=0)
{
l=l+j;
}
}
printf("%d\n",l);
}
}
return 0;
}
//Happy_Coding
#include<stdio.h>
main()
{
int i,j,k,l=0,x,y,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
if(x>y)
{
for(j=y+1,l=0;j<x;j++)
{
if(j%2!=0)
{
l=l+j;
}
}
printf("%d\n",l);
}
else
{
for(j=x+1,l=0;j<y;j++)
{
if(j%2!=0)
{
l=l+j;
}
}
printf("%d\n",l);
}
}
return 0;
}
No comments:
Post a Comment