This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int getMax(int x, int y) | |
{ | |
if (x > y) | |
return x; | |
else | |
return y; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() { | |
int x = 0; | |
cout << "Enter X" << endl; | |
cin >> x; | |
switch (x > 0) { | |
case true: | |
cout << "X > 0" << endl; | |
break; | |
case false: | |
cout << "X <= 0" << endl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() { | |
int NUM_ITERATIONS = 0; //number of iterations | |
int i; | |
int sum = 0; | |
cout << "Enter number of iterations" << endl; | |
cin >> NUM_ITERATIONS; | |
for (i = 0; i < NUM_ITERATIONS; i++) { | |
sum++; | |
} | |
cout << "SUM = " << sum << endl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void recur(int n) | |
{ | |
if (n > 0) { | |
cout << "1 "; | |
recur(n-1); | |
} | |
return; | |
} | |
int main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int code = 0; | |
cout << "Enter ASCII code" << endl; | |
cin >> code; | |
cout << "Symbol for this code is: " << (char) code << endl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int result=(0xFF & 5 >> 1 + 1); | |
cout << "Result = " << result << endl; | |
// Result is 1 | |
int a = 5*3; | |
float b = 1.5f; | |
b += --a/2; | |
cout << "Result2 = " << b << endl; | |
// Result is 8.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Add | |
{ public: short S1; | |
int f(int x) | |
{ return S1 + ++x;} | |
int A(short a, short b); | |
} K1; | |
int Add::A(short a, short b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int n = 10; //number of elements | |
int arr[n]; //array of n elements | |
int i,j; //array indexes | |
int temp; //temporary variable for sorting | |
srand(rand()); | |
cout << "Unsorted array:" << endl; | |
for (i = 0; i < n; i++) { | |
arr[i] = rand(); | |
cout << arr[i] << " "; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct my | |
{ | |
int a, b; | |
} m1; | |
int func(my f) | |
{ | |
return f.a + f.b++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int x = 0; | |
int* ptr; | |
x = 10; | |
ptr = &x; // Save address of x into ptr | |
cout << "X = " << x << endl; // Result is 10 | |
cout << "Y = " << *ptr << endl; // Result is 10 | |
// ============ | |
struct TwoNumbers { |
OlderNewer