习题1-1 平均数
#include <stdio.h>
int main(int argc, const char * argv[]) {
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
printf("%.3f\n",1.0*(a+b+c)/3);
return 0;
}
习题1-2 温度
#include <stdio.h>
int main(int argc, const char * argv[]) {
double f;
scanf("%lf",&f);
printf("%.3f\n",5*(f-32)/9);
return 0;
}
习题1-3 连续和
#include <stdio.h>
int main(int argc, const char * argv[]) {
int n;
scanf("%d",&n);
printf("%d\n",(1+n)*n/2);
return 0;
}
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[]) {
int n;
scanf("%d",&n);
const double pi =acos(-1.0);
printf("%.1f\n",sin(n*pi/180));//注意要把正整数换成弧度,1弧度等于pi/180
printf("%.1f\n",cos(n*pi/180));
return 0;
}
习题1-5 打折
#include <stdio.h>
#define PRICE 95
int main(int argc, const char * argv[]) {
int count;
scanf("%d",&count);
double money=count*PRICE;
if(money>=300){
money*=0.85;
}
printf("%.2lf\n",money);
return 0;
}
习题1-6 三角形
#include <stdio.h>
int main(int argc, const char * argv[]) {
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a+b>c&&a+c>b&&b+c>a&&a-b<c&&a>0&&b>0&&c>0)
if(a*a+b*b==c*c||a*a+c*c==b*b||c*c+b*b==a*a)
printf("yes\n");
else
printf("no\n");
else
printf("not a triangle\n");
return 0;
}
#include <stdio.h>
int main(int argc, const char * argv[]) {
int year;
scanf("%d",&year);
if(year%400==0||(year%4==0&&year%100!=0)){
printf("yes\n");
}
else{
printf("no\n");
}
return 0;
}