C语言,求1-1000所有奇数的和,偶数的和,倒数的和,c用while循环

Python014

C语言,求1-1000所有奇数的和,偶数的和,倒数的和,c用while循环,第1张

#include <stdio.h>

int main()

{

float i,js,os,ds

i=1

js=0os=0ds=0

while(i<=1000)

{

if(int(i)%2==0) //偶数

os+=i

else//奇数

js+=i

//倒数 

ds=ds+1/i

i++

}

printf("奇数和:%.0f\n偶数和:%0.0f\n倒数和:%f\n",js,os,ds) 

return 0

}

#include<stdio.h>

main()

{float daoshu(int a,int b)

int x,y

printf("输入区间(整数):")

scanf("%d%d",&x,&y)

printf("奇数的倒数和为:%f\n",daoshu(x,y))

}

float daoshu(int a,int b)

{

float s=0,c=1.0

int i

if(a%2==0)

a=a+1

if(b%2==0)

b=b-1

for(i=ai<=b)

{

s=s+c/i

i=i+2

}

return s

}