if(x==0 || x>=11 || y==0 || y>=11){ scanf("%hhu,%hhu",&x,&y); printf("非法坐标,请重新输入\n"); printf("x=%hhu,y=%hhu\n",&x,&y); 输入1,2打印出来的值是0,0的原因
时间: 2024-04-22 17:28:04 浏览: 33
在你的代码中,打印出来的 `x` 和 `y` 的值为 0, 0 的原因是你在 `printf` 函数中错误地使用了取地址符 `&`。在 `printf` 函数中,当你使用 `%hhu` 格式化字符来输出 `unsigned char` 类型的变量时,你应该直接传递变量的值,而不是变量的地址。
要修正这个问题,只需在 `printf` 函数中去掉 `&` 符号即可。下面是修改后的代码片段:
```c
if (x == 0 || x >= 11 || y == 0 || y >= 11) {
scanf("%hhu,%hhu", &x, &y);
printf("非法坐标,请重新输入\n");
printf("x=%hhu,y=%hhu\n", x, y); // 修正此行
}
```
这样修改后,当你输入 `1,2` 时,打印出来的值应该是 `x=1, y=2`。注意,`%hhu` 格式化字符用于输出 `unsigned char` 类型的值。
希望这可以解决你的问题!如果还有其他疑问,请随时提出。
相关问题
y=23/7|x ³+4|c语言
这个问题中提供的三个引用与y=23/7|x³+4|c语言似乎没有直接关系。但是,我们可以通过第一个引用中提供的代码来计算y=23/7|x³+4|的值。具体步骤如下:
1. 首先,我们需要将|x³+4|转换为代码中的fun函数。
2. 然后,我们需要将23/7乘以fun函数的返回值,即y=23/7*fun(x)。
3. 最后,我们需要在main函数中输入x的值,并输出计算结果。
代码如下:
```
#include <stdio.h>
#include <math.h>
int fun(int x){
int y=0;
if(x<0) y=x*x-2*x+1;
else y=x*x*x+x+3;
return y;
}
int main(){
int x=0;
printf("请输入x的值:");
scanf("%d",&x);
int y=23.0/7*fabs(fun(x));
printf("计算结果为:%d\n",y);
return 0;
}
```
y=|x|主调函数c语言
以下是一个求y=|x|的C语言主调函数的例子:
```c
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x, y;
printf("Enter a number: ");
scanf("%d", &x);
if (x < 0) {
y = -x;
} else {
y = x;
}
printf("The absolute value of %d is %d\n", x, y);
return 0;
}
```