ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2022.2.25

2022-02-26 09:30:59  阅读:191  来源: 互联网

标签:std 25 return int printf using include 2022.2


2022.2.25

第一课习题&第二课

#include<iostream>//不加iostream头文件会快很多

#include<cstdio>

using namespace std;//只用scanf可以不用加这个

int main()

{

int a, b, c, d;

scanf("%d%d%d%d", &a, &b, &c, &d);

printf("DIFERENCA = %d\n", a * b - c * d);//\n是回车的意思

return 0;

}

圆的面积

#include<cstdio>//保留小数的话,用printf会轻松

//算法题浮点数一般都用double,float精度太低。

using namespace std;

int main()

{

double pi = 3.14159,r;

scanf("%lf",&r);

printf("A=%.4lf\n",pi*r*r);//.4要放在百分号后面

return 0;

}

#include<stdio> 所有c可用的头文件在c++中都可以编译

两点间的距离

#include<cstdio>

#include<cmath>//所有和数学相关的都在cmath里

using namespace std;

int main()

{

double x1,x2,y1,y2;

scanf("%lf%lf",&x1,&y1);

scanf("%lf%lf",&x2,&y2);

printf("%.4lf\n",sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));//括号不要落下了

//^2在c++里不表示乘方的意思

return 0;

}

钞票

#include<cstdio>

using namespace std;

int main()

{

int n;

scanf("%d",&n);

printf("%d\n",n);

printf("%d nota(s) de R$ 100,00\n",n/100);

n %= 100;

printf("%d nota(s) de R$ 50,00\n",n/50);

n %= 50;

printf("%d nota(s) de R$ 20,00\n",n/20);

n %= 20;

printf("%d nota(s) de R$ 10,00\n",n/10);

n %= 10;

printf("%d nota(s) de R$ 5,00\n",n/5);

n %= 5;

printf("%d nota(s) de R$ 2,00\n",n/2);

n %= 2;

printf("%d nota(s) de R$ 1,00\n",n);

return 0;

}

时间转换

#include<cstdio>

using namespace std;

int main()

{

int a;

scanf("%d",&a);

printf("%d:%d:%d",a/3600,a%3600/60,a%60);//分钟数的要先用3600取模再整除

return 0;

}

圆的体积

#include<cstdio>

using namespace std;

int main()

{

double R;

scanf("%lf",&R);

printf("VOLUME = %.3lf",R*R*R*(4/3.0)*3.14159);//4/3得出来的是整数

return 0;

}

工资和奖金

#include<cstdio>

#include<iostream>//#include<string>在这个库里

using namespace std;

int main()

{

string name;//string只能用cin来读入

cin >> name;

double x,y;

cin >> x >> y;

printf("TOTAL = R$ %.2lf",x+y*0.15);

return 0;

}

最大值比较

#include<iostream>

using namespace std;

int main()

{

int a,b,c;

cin>>a>>b>>c;

int t=(a+b+abs(a-b))/2;//abs包含在<iostream>库里

int r=(t+c+abs(t-c))/2;//abs对小数也是成立的

cout <<r<<" eh o maior"<<endl;

return 0;

}

距离

#include<iostream>

using namespace std;

int main()

{

int l;

cin>>l;

cout<<2*l<<" minutos"<<endl;//若用l/0.5,此时输出的变量类型会转换为浮点数,因此输入较长的数字时,有效数字就不够了

return 0;

}

钞票和硬币这个题目需要注意!

天数转换

#include<iostream>

using namespace std;

int main()

{

int n;

cin>>n;

cout<<n/365<<" ano(s)"<<endl;n%=365;

cout<<n/30<<" mes(es)"<<endl;n%=30;

cout<<n<<" dia(s)"<<endl;

//cout输出时会自动换行。不用加\n

return 0;

}

 

标签:std,25,return,int,printf,using,include,2022.2
来源: https://blog.csdn.net/Bamboocandy/article/details/123145204

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有