1. 程式人生 > 實用技巧 >JavaSE05-switch多選擇結果、命令列傳參、不定項引數、遞迴

JavaSE05-switch多選擇結果、命令列傳參、不定項引數、遞迴

#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 i,m,n,hsy;
    for(n=101;n<=200;n++){
        m=sqrt(n);
        for(i=2;i<=m;i++){
            if(n%i==0)break;
        }
        if(i>m){
            printf("%d\n",n);
            hsy++;
            if(hsy%5==0){
            printf("\n");
        }
    }
}
  printf("\n一共有素數%d個\n",hsy);
  return 0;
}

#include<stdio.h>
int main(){
    int x,y,m,hsy;
    printf("enter a number:");
    while(scanf("%d",&x)!=EOF){
        hsy=0;
        m=1;
        y=x%10;
        while(x>0){
            if(y%2!=0){
                hsy=y*m+hsy;
                m=m*10;
            }
            x=x/10;
            y=x%10;
        }
        printf("%d\n",hsy);
        printf("enter a number:");
    } 
    return 0;
}

#include<stdio.h>
int main(){
    int x,y,m,n;
    float s;
    printf("enter n(1`10):");
    while(scanf("%d",&n)!=EOF){
        x=1;
        y=1;
        m=1;
        s=0;
        while(y<=n){
            x=x*y;
            s=s+m/(double)x;
            m=-m;
            y++;
        } 
        printf("n=%d,s=%f\n",n,s);
        printf("enter n(1`10):");
        
    }
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main(){
    int x,y,n;
    printf("猜猜2020年12月哪一天會是你的luck day\n");
    printf("開始嘍,你有三次機會,猜吧(1`31) :");
    x=rand()%30+1;
    y=1;
    while(y<=3){
        scanf("%d",&n);
        if(x==n){
            printf("\n");
            printf("恭喜你,猜中了!");
            y=5;
             
        }
        else{
            if(x<n){
                printf("\n");
                printf("你猜的日期晚了,lucky day悄悄溜到前面了\n");
            }
            else{
                printf("\n");
                printf("你猜的日期早了,lucky day還沒到呢\n");
            }
            printf("再猜(1`31):");
            y++;
        }
    } 
    if(y==4){
        printf("次數用完了,偷偷告訴你:12月,你的lucky day是%d號",x);
        
    }
    return 0;
}