Given the following pseudocode, write a program that executes it. Use floating-point types for all values.
read x;
read y;
compute p = x * y;
compute s = x + y;
Total = s^2 + p *(s - x) * (p + y);
print total.
read x;
read y;
compute p = x * y;
compute s = x + y;
Total = s^2 + p *(s - x) * (p + y);
print total.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <iostream.h> #include <conio.h> int main () { float x, y, p, s, s2, Total; cout << " Enter a value of x? \n"; cin >> x; cout << " Enter a value of y? \n"; cin >> y; p = x * y; s = x + y; s2 = s * s; Total = s2 + (p * ((s - x) * (p + y))); cout << " s = x + y; p = x * y \n"; cout << "\n s^2 + (p * ((s - x) * (p + y))) = " << Total ; getch (); return 0; }// main |
Result:
Enter a value of x? 2 Enter a value of y? 5 s = x + y; p = x * y s^2 + (p * ((s - x) * (p + y))) = 7999
No comments:
Post a Comment