2021-02-20

7.计算分段函数:
1/x (x≠0)
y= f(x)= {
0 (x=0)
8.求出1-N中的所有素数。

9.判断一个数是否为"水仙花数",所谓"水仙花数"是指一个三位数其各位数字的立方和等于该数本身。例如:371是一个"水仙花数",371=33+73+1^3.
//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”);
}
//9
#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”);
}

上一篇:python无限保留小数


下一篇:231. 2 的幂