其他分享
首页 > 其他分享> > 2022.2.25

2022.2.25

作者:互联网

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