//// Created by lanys on 2024/6/21.// 平均数(average)#include<cstdio>intmain(){int a, b, c;scanf("%d%d%d",&a,&b,&c);// 因为结果是double类型,所以需要先将一个int型的强转为double型double avg =((double) a + b + c)/3;printf("%.3lf", avg);return0;}
1.2 温度(temperature)
//// Created by lanys on 2024/6/21.// 温度(temperature)#include<cstdio>intmain(){double f;scanf("%lf",&f);double c =5*(f -32)/9;printf("%.3lf", c);return0;}
1.3 连续和(sum)
//// Created by lanys on 2024/6/21.// 连续和(sum)#include<cstdio>intmain(){int n;scanf("%d",&n);// 前n项和的公式int sum = n *(n +1)/2;printf("%d", sum);return0;}
1.4 正弦和余弦(sin and cos)
//// Created by lanys on 2024/6/21.// 正弦和余弦(sin and cos)// 这里有一点需要注意的是,如果直接用角度计算,输出的值可能不是你所期望的,所以我先是将角度转为了弧度来计算,结果ok#include<cstdio>#include<cmath>intmain(){int n;scanf("%d",&n);// 将角度转为弧度double radius = n * M_PI /180.0;double sin_result =sin(radius);double cos_result =cos(radius);printf("sin = %.4lf, cos = %.4lf", sin_result, cos_result);return0;}
1.5 打折(discount)
//// Created by lanys on 2024/6/21.// 打折(discount)// 首先输入衣服件数,然后算出money,在判断是否满足300元来决定打折与否#include<cstdio>intmain(){int n;scanf("%d",&n);double money =95.0* n;if(money >=300) money = money *0.85;printf("%.2lf", money);return0;}
1.6 三角形(triangle)
//// Created by lanys on 2024/6/21.// 三角形(triangle)// 判断三角型是否满足两边之和大于第三边,在判断是否满足直接三角形的条件#include<cstdio>intmain(){int a, b, c;scanf("%d%d%d",&a,&b,&c);if(a + b > c && a + c > b && b + c > a){if(a * a + b * b == c * c || b * b + c * c == a * a || a * a + c * c == b * b)printf("yes");elseprintf("no");}elseprintf("not a triangle");return0;}
1.7 年份(year)
//// Created by lanys on 2024/6/21.// 年份(year)// 如果能被4整除并且不能被100整除是闰年,能被400整除是闰年#include<cstdio>intmain(){int year;scanf("%d",&year);if(year %4==0&& year %100!=0|| year %400==0)printf("yes");elseprintf("no");return0;}