1. Write a complete program that declares an integer variable, reads a value from the keyboard into that variable, and writes to standard output the square of the variable's value. Besides the number, nothing else should be written to standard output.
# include <iostream> using namespace std ; int main ( ) { int x ; cin >> x ; cout << x * x ; return 0 ; }
2. Write a complete program that declares an integer variable, reads a value from the keyboard into that variable, and writes to standard output the variable's value, twice the value, and the square of the value, separated by spaces. Besides the numbers, nothing else should be written to standard output except for spaces separating the values.
# include <iostream> using namespace std ; int main ( ) { int x ; cin >> x ; cout << x << "`" << 2 * x << "`" << x * x ; return 0 ; }
No comments:
Post a Comment