• 作业3


    1.

    #include<stdio.h>
    int main(void)
    {
        int x,y;
        printf("Enter x:\n");
        scanf("%d",&x);
        if(x<0){
          y = -1;
        }
        else if(x==0){
          y=0;
        }
        else{
    
    
            y=1;
            
        }
       printf("y=%d\n",y); 
       return 0;
    }

    2.

    #include<stdio.h>
    int main (void)
    {
        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;
    }

    3.

    #include<stdio.h>
    int main(void)
    {
        int blank,digit,other,letter;
        char ch;
        int i;
        blank=digit=other=letter=0;
        printf("Enter 15 characters :");
        for(i=1;i<=15;i++){
        ch=getchar( );
        if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z'))
            letter++;
        else if(ch>='0'&&ch<='9')
            digit++;
        else if(ch>=' '&&ch<=' ')
    
    
    
            blank++;
        else
            other++;
        }
    
    printf("blank=%d,digit=%d,letter=%d,other=%d\n",blank,digit,letter,other);
        return 0;
    }

    4.

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

    5.

    #include<stdio.h>
    int main(void)
    {
        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;
    }

    6.

    #include<stdio.h>
    int main(void)
    {
        int choice,i;
        double price;
        for(i=1;i<=5;i++){
            printf("[1]select apples\n");
            printf("[2]select pears\n");
            printf("[3]select oranges\n");
            printf("[4]select grapes\n");
            printf("[0]select Exit\n");
            printf("Enter choice:");
            scanf("%d",&choice);
            if(choice==0)
                break;
            switch(choice){
                   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=%0.2f\n",price);
            }
            printf("Thanks\n");
            return 0;
        }

  • 相关阅读:
    Debian常用操作
    debian-11.0.0-amd64
    CentOS-8.4.2105-x86_64
    第20章: 二进制方式部署K8S1.20高可用集群
    天狮集团云函数实践:自定义业务逻辑实现跨境电商全球直播
    峰值利用率80%+,视频云离线转码自研上云TKE实践
    腾讯首个CNCF沙箱开源项目
    斗鱼直播云原生实践之注册中心篇
    Superedge的新特性和未来之路
    腾讯云与 Grafana Labs 达成深度合作, 推出全新 Grafana 托管服务
  • 原文地址:https://www.cnblogs.com/tangxumin25/p/3379621.html
Copyright © 2020-2023  润新知