作业五
#include<stdio.h> double sign(int x) { double y; if(x>0) y=1; else if(x<0) y=-1; else y=0; return y; } int main() { int x; double y; printf("Input x:"); scanf("%d",&x); y=sign(x); printf("f(x)=%.0lf",y); return 0; }
#include<stdio.h> double even(int n) { if(n%2==0) return 1; else return 0; } int main() { int n,sum=0; double num; printf("Input n:\n"); while(n>0){ scanf("%d",&n); num=even(n); if(0==num){ printf("是奇数\n"); sum=sum+n; } else if(1==num){ printf("是偶数\n"); } else{ printf("Unknow"); } } printf("奇数和=%d",sum); return 0; }
#include<stdio.h> #include<math.h> int prime(int m){ int i,n; if(m==1)return 0; n=sqrt(m); for(i=2;i<=n;i++) if(m%i==0){ return 0; } return 1; } int main() { int sum=0,m,h=0,n;/*h为素数合*/ printf("Input m,n:"); scanf("%d%d",&m,&n);/*1<=m n<=500*/ for(m;m<=n;m++){ if(prime (m)!=0){ h=h+m; sum++; } } printf("素数的个数为:%d,素数的合为:%d",sum,h); return 0; }
#include<Stdio.h> #include<math.h> double countdigit(int number,int digit) { int n,digit1,i,y=0; double sum,sum1=0; digit1=number*10; scanf("%d",&n); for(i=1;i<=n;i++){ digit1=digit1/10; y=digit1%10; if(y==digit){ sum1++; } } printf("该数字中%d的个数为%.0lf",digit,sum1); return sum; } int main() { int digit=0,y=0,number,i,n; double sum,sum1=0; printf("Input number,digit,n(n为输入数字位数):"); scanf("%d%d",&number,&digit); sum=countdigit(number,digit); return 0; }
#include<stdio.h> #include<math.h> int number(int m,int n){ for(m;m<n;m++){ int digit=m; int digit1=0,digit2=0,digit3=0; digit1=digit/100;digit%=100; digit2=digit/10; digit3=digit%10; if(pow(digit1,3)+pow(digit2,3)+pow(digit3,3)==m){ printf("%dÊÇË®ÏÉ»¨Êý\n",m); } }return 0; } int main() { int m,n; printf("Input m,n:"); scanf("%d%d",&m,&n); number(m,n); return 0; }