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

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

🪻1.A+B

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

#include<iostream>
using namespace std;
int main()
{
    int A,B;
    cin>>A>>B;
    cout<<A+B<<endl;
    return 0;
}

🪻2.差


代码如下:

#include<iostream>
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;
}

🪻3.圆的面积


代码如下:

#include <iostream>
using namespace std;
int main()
{
    double r,A;
    cin>>r;
    A=3.14159*r*r;
    printf("A=%.4f",A);
    return 0;
}

🪻4.平均数1


代码如下:

#include <iostream>
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;
}

🪻5.工资


代码如下:

#include <iostream>
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;
}

🪻6.油耗


代码如下:

#include <iostream>
using namespace std;
int main()
{
    int X;//行驶总路程
    double Y;//油量
    cin>>X;
    cin>>Y;
    printf("%.3f km/l",X/Y);
    return 0;
}

🪻7.两点间的距离


代码如下:

#include <iostream>
#include <cmath>
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;
}

🪻8.钞票



代码如下:

#include <iostream>
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;
}

🪻9.时间和转换


代码如下:

#include <iostream>
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;
}

🪻10.简单乘积


代码如下:

#include<iostream>
using namespace std;
int main()
{
    int A,B;
    cin>>A;
    cin>>B;
    cout<<"PROD = "<<A*B<<endl;
    return 0;
}

🪻11.简单计算



代码如下:

#include <iostream>
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;
}

🪻12.球的体积


代码如下:

#include  <iostream>
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;
}

🪻13.面积



代码如下:

#include <iostream>
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;
}

🪻14.平均数2


代码如下:

#include <iostream>
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;
}

🪻15.工资和奖金



代码如下:

#include <iostream>
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;
}

🪻16.最大值

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

#include <iostream>
#include <cmath>
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;
}

🪻17.距离


代码如下:

#include <iostream>
using namespace std;
int main()
{
    int L,X;
    cin>>L;
    X=L*2;
    cout<<X<<" minutos";
    return 0;
}

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

🪻18.燃料消耗


代码如下:

#include <iostream>
using namespace std;
int main()
{
    int v;
    double t;
    cin>>t>>v;
    double total;
    total=t*v/12.0;
    printf("%.3f",total);
    return 0;
}

🪻19.天数转换


代码如下:

#include <iostream>
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. 三:C语言-输入输出

    2024-03-10 17:50:01       46 阅读
  2. 【Python入门进阶】1基本输入输出

    2024-03-10 17:50:01       24 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-10 17:50:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-10 17:50:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-10 17:50:01       82 阅读
  4. Python语言-面向对象

    2024-03-10 17:50:01       91 阅读

热门阅读

  1. Vue 导出前端数据报表为xlsx文件

    2024-03-10 17:50:01       45 阅读
  2. 在 build.gradle.kts 添加 阿里云仓库

    2024-03-10 17:50:01       47 阅读
  3. 青创智通:工业互联网(IOT)的发展趋势

    2024-03-10 17:50:01       42 阅读
  4. MIT 6.858 计算机系统安全讲义 2014 秋季(四)

    2024-03-10 17:50:01       40 阅读
  5. centos cat命令

    2024-03-10 17:50:01       40 阅读
  6. 分布式概念-理论篇

    2024-03-10 17:50:01       46 阅读
  7. 大数据开发(Hadoop面试真题-卷七)

    2024-03-10 17:50:01       40 阅读
  8. C#使用自定义的方法设计堆栈类

    2024-03-10 17:50:01       45 阅读