c语言编程问题1

来源:百度知道 编辑:UC知道 时间:2024/05/11 12:56:33
编程题:

(1)编程判断输入的整数x的正负性和奇偶性

(2)计算S=1+1/2+1/3+1/4+1/5+……+1/20的值并输出。

大家帮忙坐下,谢谢了,一共有18道题,为了速度求得答案我分9次问,希望大家帮帮我,谢谢谢谢。
如果有人能直接帮我做18道题,我直接给500分,能帮我的朋友M我。谢谢

(1)
#include<stdio.h>
int main()
{
int x;
scanf("%d",&x);
if (x>0) printf("It is a positive number!\n");
else if (x==0) printf("It is 0\n");
else printf("It is a negtive number!\n");
if (x%2==1) printf("It is an odd number!\n");
else printf("It is not an odd number!\n");
return 0;
}
(2)
#include<stdio.h>
int main()
{
double s=0;
int i;
for (i=20;i>=1;i--)//减少精度损失
s+=1.0/(double)i;
printf("%lf\n",s);
return 0;
}