我在国外自学c++,请高手给些详细指点

来源:百度知道 编辑:UC知道 时间:2024/06/01 06:36:26
学习点
􀂄 The switch statement
􀂄 The break statement
􀂄 The continue statement
􀂄 The goto statement

Write a C program that calculates and displays
values for z when

z = ( x*x*x - 4*x*y*y*y - 3*y*y - x )/(x*x - 2*x*y + y*y )

􀂄 Your program should calculate z for values of x
ranging between 5 to 10 and value of y ranging
between 3 to 8.
􀂄 Use a pair of nested for loops to generate the x and
y values. The x variables should control the outer
loop and be incremented in steps of 1 and y should
be incremented in steps of 1.
􀂄 Your program should also display the message
“Function Undefined” when denominator is zero.
输出结果:
x y z
-----------------------
5 3 -111.750000
5 4 -1208.000000
5 5 Function Undefined
5 6 -4308.000000
5 7 -1721.750000
5 8 -1145.777778

#include <stdio.h>

void main() {
float x;
float y;
float fNum;
float fDen;

printf( "x y z\n-----------------------\n" );
for ( x = 5.0; x <= 10.0; x += 1.0 ) {
for ( y = 3.0; y <= 8.0; y += 1.0 ) {
printf( "%.0f %.0f ", x, y );
fDen = x * x - 2 * x * y + y * y;
if ( fDen == 0.0 ) {
printf( "Function Undefined\n" );
} else {
fNum = x * x * x - 4 * x * y * y * y - 3 * y * y - x;
printf( "%.6f\n", ( fNum / fDen ) );
}
}
}
}