五则计算器
#include <stdio.h>
int main() {
int first;
int second;
char operator;
scanf("%d%c%d", &first, &operator,&second);
if(operator=='+'){
printf("=%d",first+second);
}else if(operator=='-'){
printf("=%d",first-second);
} else if(operator=='*'){
printf("=%d",first*second);
} else if (operator=='/'){
printf("=%d",first/second);
}else{
printf("=%d",first%second);
}
return 0;
}
#include <stdio.h>
int main() {
int year;
// 从用户处获得一个不大于 3000 的年份
scanf("%d", &year);
// 在下面完成你的逻辑
if((year%100!=0&&year%4==0)||year%400==0){
printf("YES");
}
else{
printf("NO");
}
return 0;
}
选择分支结构
#include <stdio.h>
int main() {
int first;
int second;
char operator;
scanf("%d%c%d", &first, &operator, &second);
switch(operator){
case'+':printf("=%d",first+second);
break;
case'-':printf("=%d",first-second);
break;
case'*':printf("=%d",first*second);
break;
case'/':printf("=%d",first/second);
break;
case'%':printf("=%d",first%second);
break;}
return 0;
}
矩形面积与周长
#include <stdio.h>
int main() {
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", a * 2 + b * 2);
printf("%d", a*b);
return 0;
}
三角形面积与周长
#include <stdio.h>
#include <math.h>
int main() {
double a, b;
scanf("%lf%lf", &a, &b);
printf("%.2lf\n", a + b + sqrt(pow(a,2) + b*b));
printf("%.2lf", (a * b) / 2);
return 0;
}
圆形面积与周长
#include <stdio.h>
#define PI 3.14
int main() {
double r;
scanf("%lf", &r);
printf("%.2lf\n", 2 * PI * r);
printf("%.2lf", PI * r * r);
return 0;
}
表示解题方法不唯一,有很多很多种写法。