C语言实验作业4

第一次作业

#include<stdio.h>
int main()
{
 int t;
 double s,m,m1;
 printf("Enter t:");
 scanf("%d",&t);
 printf("Enter s:");
 scanf("%lf",&s);
 if(t%5==0){
  m1=2*(t/5);
   }
 else{
  m1=(t-t%5)/5*2;
 }
 if(s<=3){
  m=10;
   }
 else{
  if(s<=10){
   m=m1+10+(s-3)*2;
  }
  else{
   m=m1+24+(s-10)*3;
 }}
 printf("m=%.0f\n",m);
 return 0;

}

第二次作业

#include<stdio.h>
#include<math.h>
int main()
{
 double x1,x2,x3,y1,y2,y3,s,c,i,p1,p2,p3,x,y,z;
 printf("Enter x1,y1:");
 scanf("%lf%lf",&x1,&y1);
 printf("Enter x2,y2:");
 scanf("%lf%lf",&x2,&y2);
 printf("Enter x3,y3:");
 scanf("%lf%lf",&x3,&y3);
 x=(x1-x2)*(x1-x2)+(y2-y1)*(y2-y1);
 y=(x2-x3)*(x2-x3)+(y2-y3)*(y2-y3);
 z=(x1-x3)*(x1-x3)+(y1-y3)*(y1-y3);
 p1=sqrt(x);
 p2=sqrt(y);
 p3=sqrt(z);
 i=(p1+p2+p3)/2;
 if(p1+p2>p3&&p1+p3>p2&&p2+p3>p1){
   printf("三个坐标点能构成一个三角形\n");
   c=p1+p2+p3;
   s=sqrt(i*(i-p1)*(i-p2)*(i-p3));
 }
 else{
  c=0;
  s=0;
  printf("Impossible\n");
 }
 printf("c=%.2f,s=%.2f\n",c,s);
 return 0;
}

在完成这里两个题目后,对C语言中if语句更加熟练了,但在编程过程中仍然遇到了一些问题,在第二个题目中在执行else语句后原本不需要执行的语句也执行了出来,且输出为乱码,在多次查找资料后仍不清楚。在询问过老师后得到了解答,对于这类情况也更加明了了。

posted @ 2019-04-09 17:12  杨昌益  阅读(231)  评论(1编辑  收藏  举报