算法入门经典-1

#include <iostream>
using namespace std;
int main()
{
	double a,b,c;
	cin >> a >> b >> c;
	cout.setf(ios_base::fixed,ios_base::floatfield);
	cout.precision(3);
	cout << (a+b+c)/3 << endl;
	return 0;
}
/*习题1-1*/


#include <iostream>
using namespace std;
int main()
{
	double f;
	cin >> f;
	cout.setf(ios_base::fixed,ios_base::floatfield);
	cout.precision(3);
	cout << 5*(f-32)/9 <<endl;
	return 0;
}
/*课后习题1-2*/



#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int sum = 0;
	for(int i = 1; i<=n; i++)
	{
		sum +=i;
	}
	cout << sum <<endl;
	return 0;
}
/*课后习题1-3,求和输出*/


#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	double n;
	cin >> n;
	cout << sin(n) << " " << cos(n) << endl;
	return 0;
}
/*输出正弦余弦值1-4
  有待再改改
*/


#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	double x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << sqrt(pow(fabs(x1-x2),2) + pow(fabs(y1-y2),2)) <<endl;
	return 0;
}
/*math.h函数中(1-5)
 --int abs(int i) 求整型的绝对值
   double fabs(double) 求实型的绝对值
   double cabs(struct complex znum) 求复数的绝对值
 --double pow(double x,double y) 计算以x为底数的y次幂
 --double sqrt(double) 开平方
*/


#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	if(n%2 == 0)
		cout << "yes" << endl;
	else 
		cout << "no" << endl;
	return 0;
}
/*判断偶数奇数1-6*/


#include <iostream>
using namespace std;
int main()
{
	const double discount = 0.85;
	const double minConsume = 300;
	const double single = 95;
	int n;
	cin >> n;
	double sum;
	sum = n*single;
	if(sum > minConsume)
	{
		sum *= discount;
	}
	cout.setf(ios_base::fixed,ios_base::floatfield);
	cout.precision(3);
	cout << sum << endl;
	return 0;
}
/*衣服折扣1-7*/


#include <iostream>
using namespace std;
int main()
{
	float n;
	cin >> n;
	cout.setf(ios_base::fixed,ios_base::floatfield);
	cout.precision(2);
	if(n>0)
		//printf("%.2f\n",n);
		cout << n << endl;
	else
	    //printf("%.2f\n",0-n);
		cout << 0-n <<endl;
	return 0;
}
/*浮点数绝对值固定小数位输出(会四舍五入)1-8*/


#include <iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if(a+b<=c || a+c<=b || b+c<=a)
	{
		cout << "not a triangle" << endl;
		return 0;
	}
	int max = a;
	if(max<b)
	{
		max = b;
		b = a;
		a = max;
	}
	if(max<c)
	{
		max = c;
		c = a;
		a = max;
	}
	if(a*a == b*b + c*c)
		cout << "yes" << endl;
	else
		cout << "no" << endl;
	return 0;
}

/*三角形判断1-9*/


#include <iostream>
using namespace std;
int main()
{
	int year;
	cin >> year;
	if(year%100 != 0 && year%4 == 0 || year%400 == 0)
		cout << "yes" << endl;
	else
		cout << "no" << endl;
	return 0;
}
/*闰年判断1-10*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值