c语言实验二
一:
#include "stdio.h" int main () { char a,b,c,d,e; a=getchar(); b=getchar(); c=getchar(); d=getchar(); e=getchar(); putchar(a); putchar(b); putchar(c); putchar(d); putchar(e); return 0; }
二:
#include "stdio.h" int main() { int year; printf("input the year:"); scanf ("%d", &year); if(((year%100!=0)&&(year%4==0))||(year%400==0)) printf("year:%d,month:2,days:29\n", year); else printf("year:%d,month:2,days:28\n", year); return 0; }
三:
#include "stdio.h" #include "math.h" int main() { int a,b,c; scanf ("%d",&a); scanf ("%d",&b); scanf ("%d",&c); if ((a+b>c)&&(a+c>b)&&(b+c>a)) if(a==b&&b==c) printf("等边三角形\n"); else if(pow(a,2)+pow(b,2)==pow(c,2)||pow(a,2)+pow(c,2)==pow(b,2)||pow(c,2)+pow(b,2)==pow(a,2)) if(a==b||a==c||b==c) printf("等腰直角三角形\n"); else printf("直角三角形\n"); else if(a==b||b==c||a==c) printf("等腰三角形\n"); else printf("一般三角形\n"); else printf("不是三角形\n"); return 0; }
四:
#include "stdio.h" int main() { double a, b, rate; scanf("%lf", &a); if(a<500) rate=0; else if(a>=500&&a<1000) rate=0.05; else if(a>=1000&&a<2000) rate=0.08; else if(a>=2000&&a<5000) rate=0.1; else rate=0.15; b=rate*100; switch ((int)b) { case 0: printf("a=%lf rate=%lf tax=%lf profit=%lf\n",a,rate,a*rate,a*(1-rate));break; case 5: printf("a=%lf rate=%lf tax=%lf profit=%lf\n",a,rate,a*rate,a*(1-rate));break; case 8: printf("a=%lf rate=%lf tax=%lf profit=%lf\n",a,rate,a*rate,a*(1-rate));break; case 10: printf("a=%lf rate=%lf tax=%lf profit=%lf\n",a,rate,a*rate,a*(1-rate));break; case 15: printf("a=%lf rate=%lf tax=%lf profit=%lf\n",a,rate,a*rate,a*(1-rate));break; default:printf("You wrong!\n"); } return 0; }