設計模式——橋接模式
阿新 • • 發佈:2020-11-19
#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 main() { int x, y, z; for(x=0,z=101;z<=200;z++) { for(y=2;y<=sqrt(z);y++) if(z%y==0)break; if(y>sqrt(z)) { printf("%4d",z); x++; if(x%5==0) printf("\n"); } } printf("\n101~200之間共有%d個素數",x); return 0; }
#include<stdio.h> int main() { long a, b, c, d, e; printf("Enter a number: "); while((scanf("%d",&a))!=EOF) { d=0; e=0; while(a!=0){ b=a%10; a=a/10; if((b%2)!=0) d=d*10+b; } while(d!=0) { c=d%10; d=d/10; e=e*10+c; } printf("new number is: %d\n\n",e); printf("Enter a number: "); } return 0; }
#include<stdio.h> #include<math.h> int main() { int n; printf("Enter n(1~10):"); while(scanf("%d",&n)!=EOF) { if(n<1||n>10) { return 1; }
#include<stdio.h> int main() { int a, b, c; b=1; c=6; printf("猜猜2020年12月哪一天會是你的luck day\n"); printf("開始嘍,你有三次機會,猜吧(1~31): "); scanf("%d",&a); while(b<3) { if(a>c) printf("你猜的日期晚了,luck day悄悄溜到前面啦\n"); else if(a<c) printf("你猜的日期早了,luck day話沒到呢\n"); else { printf("恭喜你猜對了!\n"); break; } printf("再猜(1~31): "); scanf("%d",&a); b++; } if (b>=3&&a!=c) printf("次數用完了,偷偷告訴你:12月,你的luck day是6號"); else if(b>=3&&a==c) printf("恭喜你猜對了!"); return 0; }
double a=0,b=0,c=1; int i; for(i=1;i<=n;i++) { b=pow((-1.0),(i+1)); c*=i; a+=b*(1.0/c); } printf("n=%d,a=%lf\n\n",n,a); printf("Enter n(1~10):"); } return 0; }