• 【语法基础练习】1.变量、输入输出、表达式与顺序语句


    文章简介:下面的题目是AcWing网站语法基础练习篇的第一小节,内容基础,难度:易。
    主要都是简单的输入输出练习。仅以此记录自己的学习。

    🪻1.A+B

    在这里插入图片描述
    代码如下:

    #include
    using namespace std;
    int main()
    {
        int A,B;
        cin>>A>>B;
        cout<<A+B<<endl;
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    🪻2.差


    代码如下:

    #include
    using namespace std;
    int main()
    {
        int A,B,C,D;
        cin>>A;
        cin>>B;
        cin>>C;
        cin>>D;
        cout<<"DIFERENCA = "<<(A*B-C*D)<<endl;
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    🪻3.圆的面积


    代码如下:

    #include 
    using namespace std;
    int main()
    {
        double r,A;
        cin>>r;
        A=3.14159*r*r;
        printf("A=%.4f",A);
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    🪻4.平均数1


    代码如下:

    #include 
    using namespace std;
    int main()
    {
        double A,B,S;
        cin>>A;
        cin>>B;
        S=(A*3.5+B*7.5)/11;
        printf("MEDIA = %.5f",S);
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    🪻5.工资


    代码如下:

    #include 
    using namespace std;
    int main()
    {
        int id;//编号
        int hour; //时长
        double salary;//时薪
        cin>>id;
        cin>>hour;
        cin>>salary;
        cout<<"NUMBER = "<<id<<endl;
        printf("SALARY = U$ %.2f",hour*salary);
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    🪻6.油耗


    代码如下:

    #include 
    using namespace std;
    int main()
    {
        int X;//行驶总路程
        double Y;//油量
        cin>>X;
        cin>>Y;
        printf("%.3f km/l",X/Y);
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    🪻7.两点间的距离


    代码如下:

    #include 
    #include 
    using namespace std;
    int main()
    {
        double x1,x2,y1,y2,d;
        cin>>x1>>y1;
        cin>>x2>>y2;
        d=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
        printf("%.4f",d);
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    🪻8.钞票



    代码如下:

    #include 
    using namespace std;
    int main()
    {
        int N;
        cin>>N;
        int R100,R50,R20,R10,R5,R2,R1;
        int t;//临时变量
        R100=N/100;
        t=N-R100*100;
        R50=t/50;
        t=t-R50*50;
        R20=t/20;
        t=t-R20*20;
        R10=t/10;
        t=t-R10*10;
        R5=t/5;
        t=t-R5*5;
        R2=t/2;
        t=t-R2*2;
        R1=t;
        cout<<N<<endl;
        cout<<R100<<" "<<"nota(s) de R$ 100,00"<<endl;
        cout<<R50<<" "<<"nota(s) de R$ 50,00"<<endl;
        cout<<R20<<" "<<"nota(s) de R$ 20,00"<<endl;
        cout<<R10<<" "<<"nota(s) de R$ 10,00"<<endl;
        cout<<R5<<" "<<"nota(s) de R$ 5,00"<<endl;
        cout<<R2<<" "<<"nota(s) de R$ 2,00"<<endl;
        cout<<R1<<" "<<"nota(s) de R$ 1,00"<<endl;
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    🪻9.时间和转换


    代码如下:

    #include 
    using namespace std;
    int main()
    {
        int N;
        int hour,min,sec;
        int t;
        cin>>N;
        hour=N/3600;
        t=N-hour*3600;
        min=t/60;
        t=t-min*60;
        sec=t;
        cout<<hour<<":"<<min<<":"<<sec;
        return 0;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    🪻10.简单乘积


    代码如下:

    #include
    using namespace std;
    int main()
    {
        int A,B;
        cin>>A;
        cin>>B;
        cout<<"PROD = "<<A*B<<endl;
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    🪻11.简单计算



    代码如下:

    #include 
    using namespace std;
    int main()
    {
        int num1,num2,amount1,amount2;
        double price1,price2;
        cin>>num1>>amount1>>price1;
        cin>>num2>>amount2>>price2;
        printf("VALOR A PAGAR: R$ %.2f",amount1*price1+amount2*price2);
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    🪻12.球的体积


    代码如下:

    #include  
    using namespace std;
    int main()
    {
        double  R,V;
        cin>>R;
        V=(4/3.0)*3.14159*R*R*R;
        printf("VOLUME = %.3f",V);
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    🪻13.面积



    代码如下:

    #include 
    using namespace std;
    int main()
    {
        double A,B,C;
        double S1,S2,S3,S4,S5;
        cin>>A>>B>>C;
        S1=0.5*A*C;
        S2=3.14159*C*C;
        S3=0.5*(A+B)*C;
        S4=B*B;
        S5=A*B;
        printf("TRIANGULO: %.3f\n",S1);
        printf("CIRCULO: %.3f\n",S2);
        printf("TRAPEZIO: %.3f\n",S3);
        printf("QUADRADO: %.3f\n",S4);
        printf("RETANGULO: %.3f\n",S5);
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    🪻14.平均数2


    代码如下:

    #include 
    using namespace std;
    int main()
    {
        double A,B,C,S;
        cin>>A;
        cin>>B;
        cin>>C;
        S=(A*2+B*3+C*5)/10;
        printf("MEDIA = %.1f",S);
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    🪻15.工资和奖金



    代码如下:

    #include 
    using namespace std;
    int main()
    {
        string name;
        double salary,sales,P;
        cin>>name>>salary>>sales;
        P=salary+sales*0.15;
        printf("TOTAL = R$ %.2f",P);
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    🪻16.最大值

    在这里插入图片描述
    代码如下:

    #include 
    #include 
    using namespace std;
    int main()
    {
        int A,B,C;
        cin>>A>>B>>C;
        int max;
        max=0.5*(A+B+abs(A-B));
        max=0.5*(max+C+abs(max-C));
        cout<<max<<" eh o maior";
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    🪻17.距离


    代码如下:

    #include 
    using namespace std;
    int main()
    {
        int L,X;
        cin>>L;
        X=L*2;
        cout<<X<<" minutos";
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    这里我第一次写得没有通过,需要注意的是,如果写成L*60/30,那么int会"爆",需要将数据类型定义为long long int。或者是直接简化。

    🪻18.燃料消耗


    代码如下:

    #include 
    using namespace std;
    int main()
    {
        int v;
        double t;
        cin>>t>>v;
        double total;
        total=t*v/12.0;
        printf("%.3f",total);
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    🪻19.天数转换


    代码如下:

    #include 
    using namespace std;
    int main()
    {
        int N;
        cin>>N;
        int t;
        int ano,mes,dia;
        ano=N/365;
        t=N-ano*365;
        mes=t/30;
        t=t-mes*30;
        dia=t;
        cout<<ano<<" ano(s)"<<endl;
        cout<<mes<<" mes(es)"<<endl;
        cout<<dia<<" dia(s)";
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
  • 相关阅读:
    设计模式之状态模式
    火线,零线,地线,你知道这三根线的作用是什么吗?
    DiskPressure(磁盘压力)
    代码随想录第五十一天 | 300.最长递增子序列 , 674. 最长连续递增序列 , 718. 最长重复子数组
    Caller 服务调用 - HttpClient
    通过jenkins进行部署java程序到centos上
    基于自适应启动策略的混合交叉动态约束多目标优化算法(MC-DCMOEA)求解CEC2015/CEC2018/CEC2023(MATLAB代码)
    学习MySQL的第二天:SQL(基础篇)
    【UI设计】使用ps软件进行一些简单的操作
    java计算机毕业设计开放式实验室预约系统源码+mysql数据库+系统+lw文档+部署
  • 原文地址:https://blog.csdn.net/2302_76305195/article/details/136460740