这个表达有什么问题? [英] What is wrong in this expression ?
问题描述
嗨我有这个代码,我不知道它有什么问题,你能帮我解决一下吗?谢谢
Hi i have this code, i don't know what is wrong in it, Can you help me to fix ? Thanks
#include<stdio.h>
#include<conio.h>
#define PI 3.1415
float aria(float);
float perimetru(float);
void main(void)
{
float L, a, l, P;
printf("\nIntroduceti valoarea L: ");
scanf("%f", &l);
printf("\nIntroduceti valoarea l: ");
scanf("%f", &L);
printf("\n=======================================");
printf("\nPatratul are:");
printf("\nl = %f ", l);
printf("\nL = %f ", L);
printf("\nperimetru = %f ", perimetru(l, L));
printf("\naria = %f", aria(l && L));
getch();
}
float aria(float)
{ float a, l, L;
a = L * l;
return a;
}
float perimetru(float)
{ float P, l , L;
P = 2*(l+L);
return P;
}
推荐答案
你想要一个清单吗?
因为编译器会给你一个免费,你不必等待......
让我们先看看你的功能来计算结果:
Would you like a list?
Because the compiler will give you one for free, and you don't have to wait at all...
Lets start by looking at your functions for working out the results:
float aria(float)
{ float a, l, L;
a = L * l;
return a;
}
float perimetru(float)
{ float P, l , L;
P = 2*(l+L);
return P;
}
您希望这些值返回什么值?
因为您在本地声明所有变量,所以 aria
相当于:
What values do you expect these to return?
Because you are declaring all your variables locally, so aria
is the equivalent of:
float aria()
{
float a;
a = 0.0 * 0.0;
return a;
}
您无法从 main
函数中的声明中访问L,a,L或P,因为它们只是在范围内,并在主
函数本身内可用。
相反,试试这个:
You can't access L, a, L, or P from the declaration in your main
function, because they are only in scope and available within the main
function itself.
Instead, try this:
float aria(float l1, float l2)
{
return l1 * l2;
}
你需要更改原型才能匹配。
然后这样称呼它:
You will need to change the prototype to match.
Then call it like this instead:
printf("\naria = %f", aria(l, L));
然后对perimetru做同样的事。
并帮自己一个忙:不要使用单个字符变量名,永远,永远,使用两个仅因情况而异的变量!将l和L放在相同的范围内是一个非常愚蠢的想法,很容易输入错误的...
Then do the same fro perimetru.
And do yourself a favour: don't use single character variable names, and never, ever, ever use two variables that only differ by case! It is a very silly idea to have "l" and "L" in the same scope as it is far, far too easy to type the wrong one...
确切的答案是。
Exact answer is.
#include<stdio.h>
#include<conio.h>
#define PI 3.1415
float aria(float,float);
float perimetru(float,float);
void main(void)
{
float L, a, l, P;
printf("\nIntroduceti valoarea L: ");
scanf("%f", &l);
printf("\nIntroduceti valoarea l: ");
scanf("%f", &L);
printf("\n=======================================");
printf("\nPatratul are:");
printf("\nl = %f ", l);
printf("\nL = %f ", L);
printf("\nperimetru = %f ",perimetru(l, L));
printf("\naria = %f", aria(l,L));
getch();
}
float aria(float l1,float L1)
{float a;
a = L1*l1;
return a;
}
float perimetru(float l2,float L2)
{ float P;
P = 2*(l2+L2);
return P;
}
这篇关于这个表达有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!