1. 程式人生 > 實用技巧 >shell 字串 表示式

shell 字串 表示式


#include<stdio.h>
#include<math.h>


void solve(double a,double b,double c);


int main(){ double a,b,c;
 printf("enter a,b,c:");
 while(scanf("%1f%1f%1f",&a,&b,&c)!=EOF){
     solve(a,b,c);
     printf("enter a,b,c:");
     
 }
 return 0;
} 



void solve(double a, double b, double
c){ double x1, x2; double delta,real,imag; if(a==0) printf("not quadratic equation.\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=%f,x2=%f\n",x1,x2); } else{real=-b/(2*a); imag
=sqrt(-delta)/(2*a); printf("x1=%f+%fi,x2=%f-%fi\n",real,imag,real,imag); } } }

宣告放在主函式之前,呼叫寫在最後 不能 根可能有多個 返回值只有一個

#include<stdio.h>
long long fac(int n);
int main(){
    int i,n;
    printf("Enter n: ");
    scanf("%d",&n);
    for(i=1;i<=n;++i){
        printf("%d!=%lld\n
",i,fac(i)); } return 0; } long long fac(int n){ static long long p=1; printf("p=%lld\n",p); p=p*n; return p; }

#include<stdio.h>
#define N 100
int fun(int n,int m,int bb[N]){
    int i,j,k=0,flag;
    for(j=n;j<=m;j++){
        flag=1;
        for(i=2;i<j;i++)
            if(j%i==0){
                flag=0;
                break;
            }
            if(flag==1)
                bb[k++]=j; 
        }
        return k;
    }

int main(){
    int n=0,m=0,i,k,bb[N];
    scanf("%d",&n);
    scanf("%d",&m);
    
    for(i=0;i<m-n;i++)
    bb[i]=0;
    
    k=fun(n,m,bb);
    
    for(i=0;i<k;i++){
        printf("%4d",bb[i]);
    }
    return 0;
}

#include<stdio.h>
#include <stdio.h>
long long fun(int n);   

int main() {
    int n;
    long long f;
    
    while(scanf("%d", &n) != EOF) {
        f = fun(n);  
        printf("n = %d, f = %lld\n", n, f);
    }
    
    return 0;
}

long long fun(int n){
    
    
     long long f;
    if(n==1)
    f=1;
    else
    f=2*fun(n-1)+1;
    return f;
}
            
        
    


    
    

#include<stdio.h>

void draw(int n,char symbol);

#include<stdio.h>
int main(){
    int n,symbol;
    
    while(scanf("%d %c",&n,&symbol)!=EOF)
    {
        draw(n,symbol);
        printf("\n");
        
    }
    return 0;
}
void draw(int n,char symbol)
{
    int i,k,j;
    
    for(i=1;i<=n;i++)
    {
        for(k=i;k<=n-1;k++)
        printf(" ");
        for(j=1;j<2*i;j++)
        {
            printf("%c",symbol);
        }
        printf("\n");
     } 
}