栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

第1讲 变量、输入输出、表达式与顺序语句

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

第1讲 变量、输入输出、表达式与顺序语句

1. A + B
#include 

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    
    cout << a + b << endl;
    
    return 0;
}
604. 圆的面积
#include 

const double pi = 3.14159;

int main ()
{
    double r;
    scanf("%lf", &r);
    
    printf("A=%.4lfn", pi * r * r);
    
    return 0;
}
  • 浮点数一般用double(精度问题)
  • 保留几位小数的时候一般用 scanf / printf 进行输入输出
605. 简单乘积
#include 

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    
    cout << "PROD = " << a * b << endl;
    
    return 0;
}
606. 平均数1
#include 

int main ()
{
    double a, b;
    scanf("%lf%lf", &a, &b);
    
    printf("MEDIA = %.5lfn", (a * 3.5 + b * 7.5) / 11);
    
    return 0;
}
607. 平均数2
#include 
#include 

using namespace std;

int main()
{
    double a, b, c;
    cin >> a >> b >> c;
    
    printf("MEDIA = %.1lfn", a * 0.2 + b * 0.3 + c * 0.5);
    
    return 0;
}
608. 差
#include 

using namespace std;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    cout << "DIFERENCA = " << a * b - c * d << endl;
    
    return 0;
}
609. 工资
#include 

int main()
{
    int number, hour;
    double money;
    scanf("%d%d%lf", &number, &hour, &money);
    
    printf("NUMBER = %dnSALARY = U$ %.2lfn", number, money * hour);
    
    return 0;
}
610. 工资和奖金
#include 
#include 

using namespace std;

int main()
{
    string name;
    double x, y;
    cin >> name >> x >> y;
    
    printf("TOTAL = R$ %.2lfn", x + 0.15 * y);
    
    return 0;
}
611. 简单计算
#include 
#include 

using namespace std;

int main()
{
    int n1, n2, s1, s2;
    double p1, p2;
    cin >> n1 >> s1 >> p1;
    cin >> n2 >> s2 >> p2;
    
    printf("VALOR A PAGAR: R$ %.2lfn", s1 * p1 + s2 * p2);
    
    return 0;
}
612. 球的体积
#include 

const double pi = 3.14159;

int main()
{
    int r;
    scanf("%d", &r);
    
    printf("VOLUME = %.3lfn", 4 / (3.0) * pi * r * r * r);
    
    return 0;
}
613. 面积
#include 

const double pi = 3.14159;

int main()
{
    double a, b, c;
    scanf("%lf%lf%lf", &a, &b, &c);
    
    printf("TRIANGULO: %.3lfn", a * c / 2);
    printf("CIRCULO: %.3lfn", pi * c * c);
    printf("TRAPEZIO: %.3lfn", (a + b) * c / 2);
    printf("QUADRADO: %.3lfn", b * b);
    printf("RETANGULO: %.3lfn", a * b);
    
    return 0;
}
614. 最大值
#include 

using namespace std;

int main ()
{
    int a, b, c, maxnum;
    cin >> a >> b >> c;
    
    maxnum = (a + b + abs(a - b)) / 2;
    maxnum = (maxnum + c + abs(maxnum - c)) / 2;
    
    cout << maxnum << " eh o maior" << endl;
    
    return 0;
}

max = (a + b + abs(a - b)) / 2;

615. 油耗
#include 

int main()
{
    int s;
    double oil;
    scanf("%d %lf", &s, &oil);
    
    printf("%.3lf km/ln", s / oil);
    
    return 0;
}
616. 两点间的距离
#include 
#include 

int main()
{
    double x1, y1, x2, y2;
    scanf("%lf%lf", &x1, &y1);
    scanf("%lf%lf", &x2, &y2);
    
    printf("%.4lfn", sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
    
    return 0;
}
617. 距离
#include 

using namespace std;

int main ()
{
    int s;
    cin >> s;
    
    cout << s * 2 << " minutos" << endl;
    
    return 0;
}
618. 燃料消耗
#include 

int main()
{
    long long s, t;
    scanf("%lld %lld", &s, &t);
    
    printf("%.3lf",s * t / 12.0);
    
    return 0;
}

// 数据范围(10^18)超过 int(2*10^9)

数据范围1018 int - 2*109

653. 钞票
#include 

using namespace std;

int main()
{
    int money;
    int cash[] = {100, 50, 20, 10, 5, 2, 1};
    cin >> money;
    
    cout << money << endl;;
    for(int i = 0; i < 7; i ++ )
    {
        cout << money / cash[i] << " nota(s) de R$ " << cash[i] << ",00" << endl;
        money -= (money / cash[i]) * cash[i];
    }
    
    return 0;
}
654. 时间转换
#include 

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    cout << n / 3600 << ":" << n % 3600 / 60 << ":" << n % 60 << endl;
    
    return 0;
}
655. 天数转换
#include 

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    cout << n / 365 << " ano(s)" << endl;
    cout << n % 365 / 30 << " mes(es)" << endl;
    cout << n % 365 % 30 << " dia(s)" << endl;
    
    return 0;
}
656. 钞票和硬币
#include 

int main()
{
    int a[] = {100, 50, 20, 10, 5, 2};
    int b[] = {100, 50, 25, 10, 5, 1};
    double money;
    scanf("%lf", &money);
	
    int n = money * 100;
    
    printf("NOTAS:n");
    for(int i = 0; i < 6; i ++ )
    {
        printf("%d nota(s) de R$ %.2lfn", n / (a[i] * 100), (double)a[i]);
        n -= n / (a[i] * 100) * (a[i] * 100);
    }
    
    printf("MOEDAS:n");
    for(int i = 0; i < 6; i ++ )
    {
        printf("%d moeda(s) de R$ %.2lfn", n / b[i], b[i] / 100.0);
        n -= n / b[i] * b[i];
    }
    return 0;
}

其他知识点
变量类型变量取值变量空间输入输出类型
boolfalse / true1B
char‘a’1B%c
int-231 ~ 231-14B%d
long long-263 ~ 263-18B%lld
float6~7 位有效数字4B%f
double15~16 位有效数字8B%lf
long double18~19 位有效数字16B%llf
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/289837.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号