当前位置:首页 > 未分类 > 正文内容

基础语法练习

admin2年前 (2024-12-15)未分类1344

基础语法练习

不放题目描述了,直接放题目链接和解题代码。

第一题:A+B

  • 解题代码:

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

第二题:差

  • 解题代码:

#include <cstdio>

int main(){
   int a,b,c,d;
   scanf("%d%d%d%d", &a, &b, &c, &d);
   printf("DIFERENCA = %d", a*b - c*d);
   return 0;
}

第三题:圆的面积

  • 解题代码:

#include <cstdio>
#include <iostream>
using namespace std;

int main(){
   double r;
   cin >> r;
   printf("A=%.4lf", 3.14159 * r * r);
   return 0;
}

第四题:平均数

  • 解题代码:

#include <cstdio>

int main(){
   double a,b;
   scanf("%lf%lf", &a, &b);
   printf("MEDIA = %.5lf", (a*3.5 + b*7.5)/(3.5 + 7.5));
   return 0;
}

第五题:工资

  • 解题代码:

#include <cstdio>
#include <iostream>
using namespace std;

int main(){
   double a,b,c;
   cin >> a >> b >> c;
   printf("NUMBER = %.0lf\n", a);
   printf("SALARY = U$ %.2lf", b*c);
   return 0;
}

第六题:油耗

  • 解题代码:

#include <cstdio>
#include <iostream>

int main(){
   double a,b;
   std::cin >> a >> b;
   printf("%.3lf km/l", a/b);
   return 0;
}

第七题:两点间的距离

  • 解题代码:

#include <cstdio>
#include <cmath>

int main(){
   double x1,y1,x2,y2;
   scanf("%lf%lf", &x1, &y1);
   scanf("%lf%lf", &x2, &y2);
   printf("%.4lf", sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)));
   return 0;
}
  • 注意事项: 计算平方根需包含cmath头文件,否则sqrt函数无法正常使用。

第八题:钞票

  • 解题代码:

#include <cstdio>
#include <iostream>
using namespace std;

int main(){
   int n;
   cin >> n;
   printf("%d\n", n);
   printf("%d nota(s) de R$ 100,00\n", n/100);
   n = n % 100;
   printf("%d nota(s) de R$ 50,00\n", n/50);
   n = n % 50;
   printf("%d nota(s) de R$ 20,00\n", n/20);
   n = n % 20;
   printf("%d nota(s) de R$ 10,00\n", n/10);
   n = n % 10;
   printf("%d nota(s) de R$ 5,00\n", n/5);
   n = n % 5;
   printf("%d nota(s) de R$ 2,00\n", n/2);
   n = n % 2;
   printf("%d nota(s) de R$ 1,00\n", n/1);
   return 0;
}

第九题:时间转换

  • 解题代码:

#include <cstdio>

int main(){
   int n,a,b,c;
   scanf("%d", &n);
   a = n / 3600; // 计算小时数
   b = n % 3600 / 60; // 计算分钟数
   c = n % 60; // 计算秒数
   printf("%d:%d:%d", a, b, c);
   return 0;
}

第十题:简单乘积

  • 解题代码:

#include <iostream>
using namespace std;

int main(){
   int a,b;
   cin >> a >> b;
   cout << "PROD = " << a*b << endl;
   return 0;
}

后续更新计划

先到这里,晚上继续更新。以上都是基础题目,适合刚开始学 C++ 的新手入门。后面会更新包含判断语句(if-else、switch 等)的题目,逐步提升语法应用难度。



扫描二维码推送至手机访问。

版权声明:本文由克拉玛依十三年年社团发布,如需转载请注明出处。

本文链接:https://www.klmyssn.com/?id=71

分享给朋友:

“基础语法练习” 的相关文章

(原创)看我用各种姿势在手机和PC查看到连接到的wifi密码

(原创)看我用各种姿势在手机和PC查看到连接到的wifi密码

今天一个女神来我家做客,她问我WiFi密码,然而我却奇迹般的忘记了(特么的当时心里一万个草泥马踏过去),让我在她面前尴尬求子的,所以为了防止你们也出现这种情况,我特地把各种方法整理了一下,那么感兴趣的朋友们继续往下看吧!用电脑的cmd命令行查看密码1.按住Windows键和R键,在跳出来的运行界面输...

(原创)一张图片,你的信息暴露无遗~

(原创)一张图片,你的信息暴露无遗~

大家好,我是 31,今天教给大家一个定位的小技巧,也没什么技术含量,看着玩就好啦~~~~昨天看到社团老大 “十三年” 在群里发照片 “装 13”,结果被我抓到了,哈哈哈哈,每个人都有大意之时。不多说,上图(居然发现手表不错,和我的一样帅~~~~~):**一、科普:什么是 Exif 数据?1. Exi...

小讲堂心得

小讲堂心得

参加小讲堂活动,是受邀两位学习部的同学十分热情的邀请,为同学们讲讲网络安全方面的知识。我感到十分荣幸,但又有些许担忧,怕讲不好,因为网络安全这个学科涉及的知识面十分宽泛,网络安全从其本质上来讲就是网络上的信息安全。从广义来说,凡是涉及到网络上信息的保密性、完整性、可用性、真实性和可控性的相关技术和理...

(原创)sqlmap 注入初级教程 [sqlmap][sqlmap 指令][sqlmap 怎么用]

(原创)sqlmap 注入初级教程 [sqlmap][sqlmap 指令][sqlmap 怎么用]

一、熟悉 sqlmap 之路:核心注入场景与方法1. Sqlmap 之 Post 注入Post 注入适用于表单提交(如登录页、数据提交页)等场景,核心是通过抓取 Post 请求数据进行注入测试,以下为 4 种常用方法:方法一:基于请求文件(-r 参数)# 基础用法(请求文件与sqlmap同目录)sq...

(原创) 校园卡破解系列之数据修改 [pm3 破解饭卡][pm3 修改数据][校园卡修改][IC 卡修改数据]

(原创) 校园卡破解系列之数据修改 [pm3 破解饭卡][pm3 修改数据][校园卡修改][IC 卡修改数据]

(二)吃不完的饭卡提升完 IC 卡权限,就该考虑能不能修改饭卡金额了。通过两次消费前后饭卡数据的对比分析,发现虽然卡片数据包含较多扇区和区块,但消费前后变化的地方仅涉及两个扇区,这为后续分析提供了便利。通过十六进制与十进制转换,可进一步拆解变化的数据:消费后金额:373.2(数字:37320;16...

(原创)Powershell And Metasploit (上)

(原创)Powershell And Metasploit (上)

00x01 #题外话作者: 墨 (X_Al3r)即刻安全:www.secist.com十三年社团:www.klmyssn.com一篇不知道该用什么名字的文章!00x02 #什么是 PowershellPowerShell 一般指 Windows Power ShellPowershell 是 Mic...