javaSE專案如何打成jar包執行
阿新 • • 發佈:2020-11-13
1.程式碼
1 #include<stdio.h> 2 #include<math.h> 3 int main(){ 4 5 float a, b, c, x1, x2; 6 float delta, real, imag; 7 printf("Enter a, b, c: "); 8 while(scanf("%f%f%f", &a, &b, &c) != EOF) { 9 if(a == 0) 10 printf("not quadratic equation.\n\n"); 11 else{ 12 delta = b*b - 4*a*c; 13 if(delta >= 0) { 14 x1 = (-b + sqrt(delta)) / (2*a); 15 x2 = (-b - sqrt(delta)) / (2*a); 16 printf("x1 = %.2f, x2 = %.2f\n\n", x1, x2); 17 } 18 else { 19 real = -b/(2*a); 20 imag = sqrt(-delta) / (2*a); 21 printf("x1 = %.2f + %.2fi, x2 = %.2f - %.2fi\n\n", real,imag, real, imag); 22 } 23 } 24 printf("Enter a, b, c: "); 25 } 26 return 0; 27 28 }
if語句需要條理清晰
結果
2.
程式碼
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 23 int main() { int x, n; srand(time(0)); // 以當前系統時間作為隨機種子n = 0; do { n++; x = rand()%10; // 生成一個0~9之間的隨機整數 printf("%3d", x); }while(n<N); printf("\n"); return 0; }
結果(這個程式執行時間意外的短?)
3.(半成品)
程式碼
1 #include <stdio.h> 2 #include<math.h> 3 #include<stdlib.h> 4 int main() 5 { 6 int b,n,i,t; 7 t=0; 8 for(n=100;n<=200;n++) 9 { 10 b=sqrt(n); 11 for(i=2;i<=b;i++) 12 if(n%i==0)break; 13 if(i>b&&n>1) 14 { 15 t++; 16 printf("%5d",n);} 17 else 18 continue; 19 20 } 21 printf("\n"); 22 printf("101-200之間一共有%d個素數\n",t); 23 return 0; 24 }
暫時還沒想出怎麼輸出成那樣3*7(再想想)
結果
4.程式碼
1 #include<stdio.h> 2 3 4 int main(){ 5 int i; 6 long int n; 7 8 printf("Enter a number:\n"); 9 while(scanf("%ld",&n)!=EOF) 10 {long int c=0;int t=1; 11 while(n!=0) 12 { 13 14 i=n%10; 15 if(i%2!=0) 16 { 17 c=c+i*t; 18 t=t*10; 19 } 20 21 n=n/10; 22 } 23 printf("%ld\n",c); 24 printf("Enter a munber:\n"); 25 } 26 27 28 29 30 return 0; 31 }
(開始忽視了int型 的特殊性,想先求出長數字的位數,走了彎路。用的是類似倒序輸出的方法輸出的)
結果
5.程式碼
1 #include<stdio.h> 2 int main() 3 { 4 int n,i,c; 5 float t; 6 printf("Enter n(1~10):"); 7 while(scanf("%d",&n)!=EOF) 8 { 9 float s=0; 10 int m=1; 11 c=-1; 12 for(i=1;i<=n;i++) 13 { 14 m=m*i; 15 c=c*(-1); 16 t=c*1.0/m; 17 s=s+t; 18 19 } 20 printf("n=%d,s=%f\n",n,s); 21 printf("\nEnter n(1~10):"); 22 } 23 return 0; 24 } 25
結果
6.程式碼(個人感覺複雜了點可以簡化)
1 /*2*/ 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<time.h> 5 int main(){ 6 int x,i; 7 int n=1; 8 srand(time(0)); 9 x = rand()%32; 10 printf("猜猜12月哪天是你的lucky day\n"); 11 printf("你有三次機會:"); 12 while(n<=3) 13 { 14 scanf("%d",&i); 15 if(n<3) 16 { 17 if(i==x) 18 { 19 printf("有內鬼,這都能猜中\n"); 20 exit(0);} 21 else if(i>x) 22 { 23 printf("這都能猜後面去\n\n"); 24 printf("再給你一次機會:\n");} 25 else if(i<x) 26 {printf("這都能猜前面去\n\n"); 27 printf("再給你一次機會:\n"); 28 } 29 } 30 else if(n=3) 31 { 32 if(i>x) 33 { 34 printf("這都能猜後面去\n\n"); 35 printf("辣雞你的lucky day是:%d",x);} 36 if(i<x) 37 { 38 printf("這都能猜前面去\n\n"); 39 printf("辣雞你的lucky day是:%d",x);} 40 41 } 42 n++; 43 } 44 return 0; 45 }
結果
感覺自己寫程式的時候總是容易把演算法搞複雜........