/*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 a,b,i,s=0;
scanf("%d%d",&a,&b);
if(a>b)
{
for(i=b+1;i<a;i++)
{
if(i%2!=0)
{
s=s+i;
}
}
}
else
{
for(i=a+1;i<b;i++)
{
if(i%2!=0)
{
s=s+i;
}
}
}
printf("%d\n",s);
return 0;
}
//Happy_Coding
#include<stdio.h>
main()
{
int a,b,i,s=0;
scanf("%d%d",&a,&b);
if(a>b)
{
for(i=b+1;i<a;i++)
{
if(i%2!=0)
{
s=s+i;
}
}
}
else
{
for(i=a+1;i<b;i++)
{
if(i%2!=0)
{
s=s+i;
}
}
}
printf("%d\n",s);
return 0;
}
No comments:
Post a Comment