【语法基础练习】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;
}
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

釉色清风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值