The C++ syntax we will add for part 2 includes:
// print the value of an integer variable, x, padded to be 6 spaces wide printf("The value is %6d", x); // print the value of a double variable, y, padded to be 5 spaces wide, // and with exactly two digits after the decimal point printf("The value is %5.2lf", y); // print the value of a float variable, z, leaving out any trailing zeros printf("The value is %g", z); |
// read an integer value into radius scanf("%d", &radius); // read a float value into circumference scanf("%f", &circumference); // read a double value into area scanf("%lf", &area); |
// include the cmath library #include <cmath> int main() { double result; // compute the square root of 32 and store it in result result = sqrt(32); // compute 5 raised to the power of 3 (i.e. 5*5*5) and store it result = pow(5, 3); } |