距離順序排列矩陣單元格
阿新 • • 發佈:2020-11-17
#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<stdlib.h> #include<math.h> int main() { int n; int i,l; int h=0; for(n=101;n<=200;n++) { for(i=2; i<=sqrt(n); i++) { if(n%i == 0) break; } if(i>sqrt(n)) { h++; printf("%d ",n); l++; if(l%5==0) printf("\n"); } } printf("\n101~200之間共有%d個素數",h); return 0; }
#include<stdio.h> #include<stdlib.h> int main() { int a,b,n; printf("Enter a number:"); while(scanf("%d",&n)!=EOF) { int c=0,i=1; while(n >= 1) { a = n%10; n = n/10; if(a%2 == 0); else { c = c+a*i; i = i*10; } } printf("new number is :%d\n\n",c); printf("Enter a number:"); } return 0; }
#include<stdio.h> #include<math.h> #include<stdlib.h> int main() { int n, i, j; double s = 0, b; printf("Enter n(1~10):"); while(scanf("%d", &n)!=EOF) { if(n >= 1 && n <= 10) { for(i = 1; i <= n; i++) { int t = 1; for(j = 1; j <= i; j++) t = t*j; b = 1.0/t; if(i%2 == 0) b = (-1)*b; s = s+b; } printf("n=%d, s=%lf\n\n",n,s); } printf("Enter n(1~10):"); } return 0; }
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int b,c = 1; srand(time(0)); int a = rand()%30+1; printf("猜猜2020年12月哪一天會是你的luck day\n\n"); printf("開始嘍,你有三次機會,猜吧(1~31):"); scanf("%d",&b); while(c <= 3) { if(c <= 3&&c!=1) { printf("\n再猜(1~31):") ; scanf("%d",&b); } if(b > a) printf("\n你猜的日期晚了,luck day悄悄溜到前面啦\n\n"); else if(b == a) printf("\n答對了\n"); else printf("\n你猜的日期早了,luck day還沒到呢\n\n"); c++; } printf("\n次數用完啦。偷偷告訴你:12月,你的luck day是%d號\n",a); return 0; }