跪求大神帮忙解出一道c语言题

2024-11-07 14:27:00
有1个网友回答
网友(1):

1.

void main(void){
    int f1=0,f2=1,i;//_____①_____
    printf(" %d %d",f1,f2 );//_____②_____
    for(i=3; i<=21; i++)//_____③_____
    {   f1=f1+f2;
        f2=f1+f2;//_____④_____
        printf(" %d %d",f1,f2);
        if((i+1)%2==0) printf("\n");
    }
}

2.

void main(void){
    FILE *fp;// _____①_____
    char c; 
    if((fp=fopen("d:\\file.dat","w"))==Null){//_____②_____原代码有错\要双写
        printf("Can't open file!\n");
        exit(0);
    }
    do{ 
        c=getchar();//不是getcher是getchar
        fputc(c,fp);//_____③_____
    }while(c!='\n');//这里少了个分号
    fclose(fp);//_____④_____
 }

3.

void main(void){
    int i,j,k;
    for(i=1; i<=3; i++){
        for(j=1; j<=3-i; j++)
            printf(" ");
        for(k=1; k<=2*i-1; k++)//_____①_____
            printf("*");
        printf("\n");
    }
    for(i=1; i<3; i++){//_____②_____
        for(j=1; j<=i; j++)//_____③_____
            printf(" ");
        for(k=1; k<=6-2*i-1; k++)
            printf("*");//_____④_____
        printf("\n");
    }
}