#include <stdio.h> int main() { double a, b; scanf("%lg%lg", &a, &b); printf("%g %g\n", a, b); printf("%g %g\n", a, b); return 0; } void RealSwap(double *x, double *y) { double t = *x; *x = *y *y = t }
时间: 2024-01-13 16:05:47 浏览: 31
您的代码还是有问题,RealSwap函数中的第三行代码缺少了分号,应该改为:
```
*x = *y;
*y = t;
```
这样就可以实现交换x和y的值了。同时,为了在main函数中调用RealSwap函数并实现交换,可以在main函数中添加以下代码:
```
RealSwap(&a, &b);
```
这样就可以将a和b的值交换了。完整代码如下:
```
#include <stdio.h>
void RealSwap(double *x, double *y) {
double t = *x;
*x = *y;
*y = t;
}
int main() {
double a, b;
scanf("%lg%lg", &a, &b);
printf("%g %g\n", a, b);
RealSwap(&a, &b);
printf("%g %g\n", a, b);
return 0;
}
```
相关问题
求两点间的距离#include <stdio.h> #include <math.h> typedef struct { double x, y; } POINT; int main() { POINT a, b; double s, p, q; scanf("%lf %lf", &a.x, &a.y); scanf("%lf %lf", &b.x, &b.y); printf("%g\n", s);
你可以使用勾股定理求解两点之间的距离,具体代码如下:
```c
#include <stdio.h>
#include <math.h>
typedef struct {
double x, y;
} POINT;
int main() {
POINT a, b;
double s, p, q;
scanf("%lf %lf", &a.x, &a.y);
scanf("%lf %lf", &b.x, &b.y);
p = a.x - b.x;
q = a.y - b.y;
s = sqrt(p * p + q * q);
printf("%g\n", s);
return 0;
}
```
其中,p和q分别代表两个点在x轴和y轴上的坐标差值,s为两点之间的距离,使用了数学库中的sqrt函数来求解根号。
#include<stdio.h> int main() { double r; int a,b,c,t; scanf("%d%d%d",&a,&b,&c); t = (a+b+c) / 2 ; area = t (t-a) (t-b) (t-c) / r; printf("%f",r); return 0; }
这段代码存在一些错误。首先,你声明了一个变量 `r`,但是没有给它赋初值。其次,你使用了一个未声明的变量 `area`,我猜测你可能想计算三角形的面积并将结果赋给它。最后,你在计算面积的公式中引用了变量 `r`,但是你没有给它赋值。
下面是修正后的代码:
```c
#include <stdio.h>
#include <math.h>
int main() {
double a, b, c, t, area;
scanf("%lf%lf%lf", &a, &b, &c);
t = (a + b + c) / 2;
area = sqrt(t * (t - a) * (t - b) * (t - c));
printf("%lf", area);
return 0;
}
```
这段代码通过 `scanf` 函数从输入中获取三角形的三边长,并使用海伦公式计算三角形的面积。修正后的代码会正确地计算并输出三角形的面积。
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![application/octet-stream](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)