代码找错,求大神!
codeblocks吧
全部回复
仅看楼主
level 8
#include <stdio.h>
#include <math.h>
typedef struct circle
{
double x;
double y;
double r;
} CIR;
CIR scan_circle (void);
void print_circle(CIR c);
int relationship (CIR c1,CIR c2);
int main ()
{
CIR c1,c2;
c1=scan_circle();
c2=scan_circle();
print_circle(c1);
print_circle(c2);
printf("%d\n",ship(c1,c2));
}
CIR scan_circle (void)
{
CIR c;
printf("请输入圆心横坐标,x=");
scanf("%lf",&c.x);
printf("请输入圆心纵坐标,y=");
scanf("%lf",&c.y);
printf("请输入圆半径,r=");
scanf("%lf",&c.r);
}
void print_circle (CIR c)
{
printf("(x,y)=(%.2f, %.2f), r=%.2f\n",c.x,c.y,c.r);
}
int relationship (CIR c1,CIR c2)
{
double l;
l=abs((c1.x-c2.x)*(c1.x-c2.x)+(c1.y-c2.y)*(c1.y-c2.y));
if (l==c1.r+c2.r||l==sqrt(c1.r-c2.r))
return 0; //printf("相切\n");
else if (abs(c1.r-c2.r)<l&&l<c1.r+c2.r)
return -1; // printf("相交\n");
else return 1 ; //printf("相离\n");
}
输出圆的那个函数!!
拜托了!
2015年04月21日 13点04分 1
level 1
#include <stdio.h>
#include <math.h>
typedef struct circle
{
double x;
double y;
double r;
} CIR;
CIR scan_circle(void);
void print_circle(CIR c);
void relationship(CIR c1, CIR c2);
int main()
{
CIR c1, c2;
c1 = scan_circle();
c2 = scan_circle();
print_circle(c1);
print_circle(c2);
relationship(c1, c2);
}
CIR scan_circle(void)
{
CIR c;
printf("请输入圆心横坐标,x=");
scanf_s("%lf", &c.x);
printf("请输入圆心纵坐标,y=");
scanf_s("%lf", &c.y);
printf("请输入圆半径,r=");
scanf_s("%lf", &c.r);
return c;
}
void print_circle(CIR c)
{
printf("(x,y)=(%.2f, %.2f), r=%.2f\n", c.x, c.y, c.r);
}
void relationship(CIR c1, CIR c2)
{
double l;
l = abs((c1.x - c2.x)*(c1.x - c2.x) + (c1.y - c2.y)*(c1.y - c2.y));
if (l == c1.r + c2.r || l == sqrt(c1.r - c2.r))
printf("相切\n");
else if (abs(c1.r - c2.r)<l&&l<c1.r + c2.r)
printf("相交\n");
else printf("相离\n");
}
我把你代码改了,你看看吧,我觉得这样更好。你犯得小错误是写错函数名了
2015年04月22日 18点04分 2
谢谢!
2015年04月23日 08点04分
弱弱的问一句,哪个函数名错了[委屈]
2015年04月23日 08点04分
回复
���ƺ�����
:main函数里面的relationship你写成了ship,还有一个我昨天没看清,你的relationship函数里面,求l的时候要开方你写成了绝对值,求半径差要绝对值你写成了开方
2015年04月23日 13点04分
level 6
进入到一个人的程序中,难度很大的,最好自己根据codeblocks提示来查找错误
2015年04月26日 07点04分 3
知道了
2015年05月04日 10点05分
1