一条简单的C语言问题求助,我是菜鸟..

来源:百度知道 编辑:UC知道 时间:2024/06/16 00:38:05
题目:
All values (x, y, p, s, total) are double:
1 read x

2 read y

3 compute p = x * y

4 compute s = x + y

5 total = s2 + p * (s - x) * (p + y)

6 print total

我的答案,可是答案总是0...
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
double x;
double y;
double p = (x*y);
double s = (x+y);
double total = (s*s)+(p*(s-x)*(p+y));
printf("please enter two number:");
scanf ("%f %f",&x,&y);
printf("\nThe total number is : \n");
printf("%d", total);
getch();
return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
double x;
double y;

printf("please enter two number:");
scanf ("%f %f",&x,&y);
double p = (x*y);
double s = (x+y);
double total = (s*s)+(p*(s-x)*(p+y));
printf("\nThe total number is : \n");
printf("%d", total);
getch();
return 0;
}

这样才是对的,你的计算p,s,total时x,y都是0,因为你的输入是在total计算出来之后的。

错误连篇!修改如下,仔细对比!原程序几乎每一行都有问题

//---------------------------------------------------------------------------

#include <stdio.h>
#include <conio.h>

int main(int argc, char *argv[])
{
double x;
double y;
double p;
double s;
double total;
printf("please enter two number:");
scanf ("%lf%lf",&x,&y);
p = (x*y);
s = (x+y);
total = (s*s)+(p*(s-x)*(p+y));