《C语言程序设计》江宝钏主编-习题4-5-边境线

AC代码:

/*《C语言程序设计》江宝钏主编-习题4-5-边境线
Description 
有一个圆,圆心坐标是(0,0),半径r=4.5,任意输入一个点的坐标(x,y),判断这个点是在圆内,圆周上,还是在圆外。
Input 
两个浮点数x,y
Output 
如果在圆内,输出in
如果在圆外,输出out
如果在圆上,输出on

Sample Input Copy 
1.0 1.0
Sample Output Copy 
in
*/

#include <stdio.h>
#include <math.h>
int main()
{
    float x,y,r1;
    scanf("%f%f",&x,&y);
    r1 = sqrt(x*x+y*y);
    if(r1<4.5)
    {
        printf("in");
    }
    else if(r1==4.5)
    {
        printf("on");
    }
    else
    {
        printf("out");
    }
    return 0;
}

//标程:
#include <stdio.h>
int main(void)
{
	float x,y,a;
	scanf("%f%f",&x,&y);
	if (sqrt(x*x+y*y) > 4.5)
	printf("out"); 
	else if (sqrt(x*x+y*y) == 4.5)
	printf("on"); 
	else if (sqrt(x*x+y*y) < 4.5)
	printf("in"); 
	return 0;
}
发布了39 篇原创文章 · 获赞 7 · 访问量 3684

猜你喜欢

转载自blog.csdn.net/qq_45599068/article/details/104089631