第四章 习题练习 第11题 第12题

第四章 习题练习 第11题
输入4个整数,要求按由小到大的顺序输出。

   #include<stdio.h>
   int main ()
{
 int a,b,c,d,e,t;
  	printf("请输入四个整数:"); 	
  	scanf("%d,%d,%d,%d",&a,&b,&c,&d); 
 	if(a > b)
 {
	t = a;
	a = b;
	b = t;
}
if(a > c)
{
	t = a;
	a = c;
	c = t;
}
if(a > d)
{
	t = a;
	a = d;
	d = t;
}
if (b > c)
{
	t = b;
	b = c;
	c = t;
}
if (b > d)
{
	t = b;
	b = d;
	d = t;
}
if (c > d)
{
	t = c;
	c = d;
	d = t;
}
printf ("从小到大排序为:%d,%d,%d,%d\n",a,b,c,d);

}

这个之前例题有讲,写起来也比较容易一些
12习题 4.12 有4个圆塔,圆心分别为(2,2)、(-2,2)、(-2,-2)、(2,-2),圆半径为1,这4个塔的高度为10m,塔以外无建筑物。今输入任一点的坐标,求该点的建筑高度(塔外的高度为零)。

犯了个低级错误

            #include <stdio.h>
      int main()
  {
float x,y;
int c,d;
printf("请按格式输入坐标(x,y): ");
scanf("%f,%f",&x,&y);
if (((x >= 1 && x <= 3)||(x >= -3 && x <= -1)) && ((y >= 1 && y <= 3)||(y >= -3 && y <= -1)))
		c = 1;
else c = 0;

switch (c)
{
case 0 :printf ("该点高度为:0\n");break;
case 1 : printf ("该点高度为:10\n");break;
}
return 0;	
}

                     圆的方程公式:(x−a)2+(y−b)2=r^2
                               (a,b)为圆心坐标r为圆心
                               

       #include <stdio.h>
          #include <math.h>
         int main()
  {
float x1= 2,y1 = 2,x2 = -2,y2 = 2,x3 = -3, y3 = -2,x4 = 2,y4 = -2,x,y,d1,d2,d3,d4;
int a ;
printf("请按格式输入坐标(x,y): ");
scanf("%f,%f",&x,&y);
d1 = pow (x - x4,2) + pow (y - y4,2);
d2 = pow (x - x1,2) + pow (y - y1,2);
d3 = pow (x - x2,2) + pow (y - y2,2);
d4 = pow (x - x3,2) + pow (y - y3,2);
if (d1 > 1 && d2 > 1 &&d3 > 1 && d4 > 1)
	h = 0;
	else h = 10;
printf ("该点高度为 :%d\n",a);
return 0;
}

其实明白方程公式的话还是比较简单的。但开始没能明白,自己研究了快一个小时,知道方程式后才会做。今天学不了第五章了,明天加油!

猜你喜欢

转载自blog.csdn.net/qq25114570/article/details/88563919