第1个回答 2015-11-21
#include<stdio.h>
void main()
{ int x,y,s=0;
scanf("%d %d",&x,&y);
if(x%2!=0)
{
for(int i=x;i<=y;i=i+2)
{printf("%d ",i);
s+=i;}
}
else
{
for(int i=x+1;i<=y;i=i+2)
{printf("%d ",i);
s+=i;}
}
printf("\ns=%d\n",s);
}
第2个回答 2015-11-21
//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
int main(void){
int x,y,sum;
while(1){
printf("Input x & y(int 0<=x<=y)...\n");
if(scanf("%d%d",&x,&y),x>=0 && x<=y)
break;
printf("Error, redo: ");
}
for(sum=0,x+=!(x&1);x<=y;sum+=x,x+=2);
printf("The result is %d\n",sum);
return 0;
}本回答被网友采纳
第3个回答 2015-11-21
#include <stdio.h>
int main()
{
int x, y, sum=0, i, t;
scanf("%d%d", &x, &y);
if(x>y)t=x,x=y,y=t;
for(i=x;i<=y;++i){
if(i%2)sum+=i;
}
printf("%d\n", sum);
return 0;
}
第4个回答 2019-05-11
#include "stdio.h"
int fun(int x,int y)
{
int i,n,s=0;
printf("x,y分别是: (x<y)");
scanf("%d,%d",&x, &y);
if(x%2==0)
{
for(i=x+2*s+1,i<=y,s++ )
n=n+i;
printf("%d",n):
{
else
{
for(i=x+2*s,i<=y,s++)
n=n+i;
printf("%d",n);
}
}