算法入门经典-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*/


©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页