实验二-用C语言编写简单程序

#include<stdio.h>
int main(void)
{
    int i;
    int fib[10]={1,1};

    for(i=2;i<10;i++)
        fib[i]=fib[i-1]+fib[i-2];

    for(i=0;i<10;i++){
        printf("%6d",fib[i]);
        if((i+1)%5==0)
            printf("\n");

    }

    return 0;


}

 

#include<stdio.h>
int main(void)
{
    double radius;

    printf("Enter radius:");
    scanf("%if",&radius);
    printf("S=%.2.0f\n",s);
    if(r<=0)
        printf("Sorry!error!\n");
    else    
        printf("s\n");
        
    s=3.14*r*r;

    return 0;

}

 

#include<stdio.h>
int main(void)
{
    int count[9];
    int i,response;
    
    for(i=1;i<=8;i++)
        count[i]=0;
    for(i=1;i<=1000;i++){
        printf("input your response:");
        scanf("%d",&response);
        if(response<1||response>8)
            printf("this is a bad response:%d\n",response);
        else
            count[response]++;
    }

    printf("result:\n");
    for(i=1;i<=8;i++)
        printf("%4d%4d\n",i,count[i]);

    return 0;

}

 

posted @ 2013-10-14 09:57  红颜文丛  阅读(158)  评论(0编辑  收藏  举报