// Simple program #include using namespace std; int main() { int x, y; x = 2; y = x + 4; cout <<" x = "<> a >> b; cout << " a = " << a << " b = " << b << endl; return 0; } Output: enter two integers:2 7 a = 2 b = 7 ========================================================= //example: a programmer-defined function #include using namespace std; int square( int ); // function prototype int main() { for ( int x = 1; x <= 10; x++ ) cout << square( x ) << " "; cout << endl; return 0; } // Function definition int square( int y ) { int result; result = y * y; return result; } Output: 1 4 9 16 25 36 49 64 81 100 ========================================================= // test on global and local variables #include using namespace std; void f12(void); int nglobal = 1; main() { cout << "main 1: nglobal = " << nglobal < using namespace std; void out2( void ); // function prototype int main() { out2(); return 0; } // Function definition void out2(void) { cout << "output from function out2"; return; } Output: output from function out2 ========================================================= // using the break statement #include using namespace std; int main () { int n; for (n = 1; n <=10; n = n+1) { if (n == 5) break; cout << n << " "; } cout << "\nBroke out of loop at n of " << n; return 0; } Output: 1 2 3 4 Broke out of loop at n of 5 ========================================================= // Using the continue statement in a for structure #include using namespace std; int main() { for ( int x=1; x<=10; x++) { if (x == 5) { continue; } cout << x << " "; } cout << "\nUsed continue to skip printing 5" << endl; return 0; } Output: 1 2 3 4 6 7 8 9 10 Used continue to skip printing 5 ========================================================= // conditional operator #include using namespace std; int main () { int a,b,c; a=2; b=7; c = (a>b) ? a : b; cout << " c = " << c; return 0; } Output: c = 7 ========================================================= // call-by-reference #include using namespace std; void f12(int&, int&); int main() { int a, b; a = 12; b = a; cout << "a = "<< a << " b = " << b <