习题1-1 平均数
#include<cstdio>
using namespace std;
int main(){
float a, b, c;
scanf("%f%f%f", &a, &b, &c);
printf("%.3f\n", (a+b+c)/3);
return 0;
}
习题1-2 温度
#include<cstdio>
using namespace std;
int main(){
float f;
scanf("%f", &f);
printf("%.3f\n", 5*(f-32)/9);
return 0;
}
习题1-3 连续和
#include<iostream>
using namespace std;
int main(){
int n, sum=0;
cin >> n;
while(n>0){
sum += n;
--n;
}
cout << sum << endl;
return 0;
}
习题1-4 正弦和余弦
#include<iostream>
#include<cmath>
#define PI 3.1415926
using namespace std;
int main(){
int n;
cin >> n;
float temp = n*PI/180;
cout << sin(temp) << " " << cos(temp) << endl;
return 0;
}
习题1-5 打折
#include<cstdio>
using namespace std;
int main(){
int n;
scanf("%d", &n);
float temp = n * 95;
if(temp < 300){
printf("%.2f\n", temp);
}
else{
printf("%.2f\n", temp * 0.85);
}
return 0;
}
习题1-6 三角形
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
int arr[3];
cin >> arr[0] >> arr[1] >> arr[2];
sort(arr, arr+3);
if((arr[0] + arr[1]) > arr[2]){
if((arr[0] -arr[1] < arr[2])){
if( (pow(arr[0], 2)+pow(arr[1],2)) == pow(arr[2], 2)){
cout << "yes" << endl;
}
else{
cout << "no" << endl;
}
}
else{
cout << "not a triangle" << endl;
}
}
else{
cout << "not a triangle" << endl;
}
return 0;
}
习题1-7 年份
#include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
if((n%4 == 0) && (n%100 != 0)){
cout << "yes" << endl;
}
else if(n%400 == 0){
cout << "yes" << endl;
}
else{
cout << "no" << endl;
}
return 0;
}