小宝的作业3-利用分支与循环结构解决问题

#include<stdio.h>
int main()
{
    int i,x;
    double price;
    
    for(i=1;i<=5;i++)
    {
        printf("[1]apples\n");
        printf("[2]pears\n");
        printf("[3]oranges\n");
        printf("[4]grapes\n");
        printf("[0]exit\n");
        printf("输入编号:\n");
        scanf("%d",&x);
        if(x==0)
            break;
        switch(x)
        {
            case 1:price=3.00;break;
            case 2:price=2.50;break;
            case 3:price=4.10;break;
            case 4:price=10.20;break;
            default:price=0.00;break;
        }
        printf("price=%.3f",price);
    }

    return 0;
}

 

#include<stdio.h>
int main()
{
    char op;
    printf("输入五级制成绩:");
    scanf("%c",&op);
    switch(op)
    {
        case'A':printf("grade=90-100");
            break;
        case'B':printf("grade=80-89");
            break;
        case'C':printf("grade=70-79");
            break;
        case'D':printf("grade=60-69");
            break;
        case'E':printf("grade=0-59");
            break;
    }

    return 0;
}

 

#include<stdio.h>
int main()
{
    int i,n,year;
    printf("Enter n:");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        printf("Enter year:");
        scanf("%d",&year);
        if((year%4==0&&year%100!=0)||(year%400==0))
        {
            printf("这是闰年");
        }
        else
        {
            printf("这不是闰年");
        }
    }


        return 0;

}

 

第三题不会。

#include<stdio.h>
int main ()
{
    int count,i,n;
    double grade,total;

    printf("Enter n:");
    scanf("%d",&n);
    total=0;
    count=0;
    for(i=1;i<=n;i++)
    {
        printf("Enter grade#%d:",i);
        scanf("%Lf",&grade);
        total=total+grade;
        if(grade>=60)
        {
            count++;
        }
    }
    printf("Grade average=%.2f\n",total/n);
    printf("Number of failures=%d\n",count);
    
    return 0;
}

 

#include<stdio.h>
int main()
{
    int x,y;
    printf("输入x:");
    scanf("%d",&x);

    if(x<0){
        y=-1;
    }
    else if(x==0)
    {
        y=0;
    }
    else
    {
        y=1;
    }
    printf("y=%d",y);

    return 0;
}

 

posted @ 2013-10-20 17:59  xiaobao123  阅读(133)  评论(0编辑  收藏  举报