最新pycharm安裝教程
阿新 • • 發佈:2020-11-20
#include<math.h> #include<stdio.h> int main(){ float a,b,c,x1,x2; float delta,real,imag; printf("Enter a,b,c;"); while(scanf("%f%f%f",&a,&b,&c ) !=EOF) { if(a==0) printf("not quadratic equation.\n\n"); else{ delta=b*b-4*a*c; if(delta>=0) { x1=(-b+sqrt(delta))/(2*a); x2=(-b-sqrt(delta))/(2*a); printf("x1=%.2f,x2=%.2f\n\n",x1,x2); } else{ real=-b/(2*a); imag=sqrt(-delta)/(2*a); printf("x1=%.2f+%.2fi,x2=%.2f-%.2fi\n\n",real,imag,real,imag); } } printf("Enter a,b,c;"); } return 0; }
#include<stdio.h> #include<stdlib.h> #include<time.h> #define N 5 int main(){ int x,n; srand(time(0)); n=0; do{ n++; x=rand()%10; printf("%3d",x); }while(n<N); printf("\n"); return 0; }
#include<stdio.h> #include<math.h> int isprime(int n); int main() { int i; for(i=101;i<200;i++) { if(isprime(i)) printf("%4d",i); } return 0; } int isprime(int n) { int k; for(k=2;k<=sqrt(n);k++) if(n%k==0) return 0; return 1; }
#include<stdio.h> int main() { int s,t=0,n; float a=0.1; printf("Enter a number:",s); while(scanf("%d",&s)!=EOF){ while(s>0){ n=s%10; s=s/10; if(n%2==1){ a=a*10; t+=n*a; } } printf("the number is:%d\n",t); printf("Enter a number:",s); } return 0; }
將其每個位上的數取出,除二取餘是否為1,高位就是乘以十再加上新的數
#include<stdio.h> #include<math.h> #include<stdlib.h> int main(){ double s; int n,sum=1,i; scanf("%d",&n); if(n<=0||n>=11) exit (0); else { for(i=n;i>0;i--) sum*=i; s=pow(-1,n-1)/sum; printf("Enter n(1~10):%d\nn=%d,s=%d\n",n,n,s); return 0; } }
#include<stdio.h> #include<stdlib.h> int main(){ int n,m=1,t; t=1+rand() %30; printf("猜猜2020年12月那一天是你的luck day\n"); printf("\n開始嘍,你有三次機會,猜吧(1~31):",n); m++; scanf("%d",&n); // m++; while(m<=3){ if(n<t){ printf("\n你猜的日期早了,luck day還沒到呢!\n"); printf("\n再猜猜:\n"); m++; scanf("%d",&n); // m++; } else if(n>t){ printf("\n你猜的日期晚了,luck day悄悄溜到後面啦!\n"); printf("\n再猜猜:\n"); m++; scanf("%d",&n); // m++; } else if(n=t) printf("\n恭喜你,猜對啦!\n"); return 0; } printf("\n次數用完啦。偷偷告訴你:12月,你的luck day是%d號\n",t); return 0; }