2021-02-20

  1. 编写1+1/2+1/3+…+1/n计算程序
  2. #include<stdio.h>
    void main()
    {
    int i,n;
    float sum=0;
    printf(“please input n:\n”);
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    sum+=1.0/i;
    }
    printf(“the result is :%f\n”,sum);
    }

#include<stdio.h>
void main()
{
int x,y;
printf(“please input x zhi:\n”);
scanf("%d",&x);
if(x<1)
y=x;
else if(x>=1&&x<10)
y=2x-1;
else
y=3
x-1;
printf(“the result is:%d\n”,y);
}
计算分段函数:
1/x (x≠0)
y= f(x)= {
0 (x=0)
8.求出1-N中的所有素数。

9.判断一个数是否为"水仙花数",所谓"水仙花数"是指一个三位数其各位数字的立方和等于该数本身。例如:371是一个"水仙花数",371=33+73+1^3.
//9
//7

#include<stdio.h>
void main()
{
float y;
int x;
printf(“please input x de zhi:\n”);
scanf("%d",&x);
if(x!=0)
y=1.0/x;
else
y=0;
printf(“the result is :%.2f\n”,y);
}
//8
#include<stdio.h>
#include<math.h>
void main()
{
int i,k,n;
printf(“please input n:\n”);
scanf("%d",&n);
k=(int)sqrt(n);
for(i=2;i<k;i++)
{
if(n%i==0)
break;
}
if(i>k)
printf(“yes”);
else
printf(“no”);
}

#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c,x;
printf(“please input x:\n”);
scanf("%d",&x);
a=x%10;
b=x/10%10;
c=x/100;
if(pow(a,3)+pow(b,3)+pow(c,3)==x)
printf(“yes”);
else
printf(“no”);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值