你能帮我解决这个问题吗? [英] Could you help me solve this problem?
本文介绍了你能帮我解决这个问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
{
int x,y;
float z;
printf( 写2个整数:);
scanf( %d%d,& x,& y);
switch (x& y)
{
案例 x + y> 0&& x + y< = 4 :
z = exp(x + y);
printf( %f是输出。\ n,z);
break ;
case x + y == 8 || x + y == 10 :
z =(pow(x, 2 )+ y) /(XY);
printf( %f是输出。\ n,z);
break ;
默认:
z = 0 ;
printf( %f是输出。\ n,z);
}
return 0 ;
}
我的尝试:
我试图添加If语句,但我不能
解决方案
您的案例陈述无效。案例使用常量值,而不是表达式。您的代码应如下所示:
int x,y;
float z;
printf( 写2个整数:);
scanf( %d%d,& x,& y);
if (x + y> 0&& x + y< = 4 )
{
z = exp(x + y);
}
其他 如果(x + y == 8 || x + y == 10 )
{
z =(pow(x, 2 跨度>)+ Y)/(XY);
}
else
z = 0 ;
// 你最后只需要一个printf来打印z的值。
printf( %f是输出。\ n,z );
解决方案1
为您提供切换的可能更正
,但由于你没有告诉我们它应该做什么,我们无法确定。
显然,你不知道<$的用法c $ c>开关。
你应该尽快正确地学习这门语言。
建议:
- 阅读语言文档,按照教程。
- 调试器是你的朋友。它会告诉你你的代码到底在做什么。
一步一步地执行,检查变量,你会发现它有一个停止做你期望的点。
掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]
http://docs.oracle .com / javase / 7 / docs / technotes / tools / windows / jdb.html [ ^ ]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]
< pre lang =c ++> #include < < span class =code-leadattribute> stdio.h >
main()
{
int x,y,w; // ad另一个整合
float z;
printf( 写2个整数:);
scanf( %d%d,& x,& y);
if ((x + y == 8 || x + y == 10 ))w = 1 ; // < span class =code-comment> state condition 0
if (x + y> 0&& x + y< = 4 )w = 0 ; // 州条件1
开关(w) // 在此替换为w
{
case 0 : // 替换为w
z = exp(x + y);
printf( %f是输出。\ n,z);
break ;
case 1 : // 在此替换为w
z =(pow(x, 2 跨度>)+ Y)/(XY);
printf( %f是输出。\ n,z);
break ;
默认:
z = 0 ;
printf( %f是输出。\ n,z);
}
return 0 ;
}
{
int x,y;
float z;
printf("Write 2 integers: ");
scanf("%d%d",&x,&y);
switch (x && y)
{
case x+y>0 && x+y<=4:
z = exp(x+y);
printf("%f is an output.\n",z);
break;
case x+y==8 || x+y==10:
z = (pow(x,2)+y)/(x-y);
printf("%f is an output.\n",z);
break;
default:
z = 0;
printf("%f is an output.\n",z);
}
return 0;
}
What I have tried:
I tried to add If statement but i couldnt
解决方案
Your case statements are not valid. Cases use constant values, not expressions. Your code should look like:
int x,y; float z; printf("Write 2 integers: "); scanf("%d%d",&x,&y); if (x+y>0 && x+y<=4) { z = exp(x+y); } else if (x+y==8 || x+y==10) { z = (pow(x,2)+y)/(x-y); } else z = 0; // you only need one printf at the end to print the value of z. printf("%f is an output.\n",z);
Solution 1
gives you a probable correction ofswitch
, but since you didn't tell us what it is supposed to do, we can't be sure.
Obviously, you don't know the usage ofswitch
.
You should properly learn the language as soon as possible.
Advice:
- read language documentation, follow tutorials.
- The debugger is your friend. It will show you what your code is really doing.
Follow the execution step by step, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]
#include<stdio.h> main() { int x,y,w; //ad another integar float z; printf("Write 2 integers: "); scanf("%d%d",&x,&y); if((x+y==8 || x+y==10)) w=1;//state condition 0 if(x+y>0 && x+y<=4) w=0;//state condition 1 switch (w) // replace here by w { case 0: // replace here by w z = exp(x+y); printf("%f is an output.\n",z); break; case 1 : // replace here by w z = (pow(x,2)+y)/(x-y); printf("%f is an output.\n",z); break; default: z = 0; printf("%f is an output.\n",z); } return 0; }
这篇关于你能帮我解决这个问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文