作业六
#include<stdio.h> int sign (int x) { if(x<0) return -1; if(x>0) return 1; else return 0; } int main() { int x; scanf("%d",&x); printf("%d\n",sign(x)); return 0; }
#include<stdio.h> int even(int n) { if(n%2==0) return 1; else return 0; } int main() { int n,x,y; printf("请输入正整数:\n"); do{ scanf("%d",&n); y=even(n); if(y==0){ x=x+n; } }while(n>0); printf("x=%d\n",x); return 0; }
#include<stdio.h> int prime (int m) { int i; for(i=2;i<=m/2;i++) if(m%i==0) return 0; else return 1; } int main() { int m,n,cnt,sum; cnt=0; sum=0; printf("请输入两个正整数:"); scanf("%d%d",&m,&n); for(m=0;m<=n;m++) { if(prime(m)) { cnt++; sum+=m; } } printf("cnt=%d,sum=%d\n",cnt,sum) return 0; }
#include<stdio.h> int countdigit(int number,int digit) { int i=0; while(number>0) { if(number%10==digit) i++; number=number/10; } return i; } int main() { int number,digit,sum; printf("请输入一个数字:\n"); scanf("%d",&number); printf("请输入要计算的数字:\n"); scanf("%d",&digit); sum=countdigit(number,digit); printf("共有%d个",sum); return 0; }
#include<stdio.h> int is(int number) { int n=0,m=0,i=0; scanf("%d%d",&n,&m); for(i=n;i<=m;i++) { if(is(i));{ printf("%d\n",i); } } { int x,y,z; x=number/100; y=number/10-i*10; z=number%10; if(number==x*x*x+y*y*y+z*z*z){ return 1; } else { return 0; } return number; } }