-
Notifications
You must be signed in to change notification settings - Fork 0
/
a_syntax.cpp
134 lines (110 loc) · 3.4 KB
/
a_syntax.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
static const int __ = []() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
return 0;
}();
// self made
const int fast = []() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
return 0;
}();
// add 2 numbers in cpp
maxPairSum = Math.Max(maxPairSum, left + right);
cout << typeid(arr[i]).name() << "\t";
const unsigned int M = 1000000007;
return sum % M;
// int ny;
// ny = std::stoi(y);
// cout<<ny<<endl;
transform(upperGreeting.begin(), upperGreeting.end(), upperGreeting.begin(),
::toupper);
// shuffling of numbers in a vector.
vector<int> shuffle() {
swap(shuffled[rand() % n], shuffled[rand() % n]);
return shuffled;
}
}
;
//
transform(s.begin(), s.end(), s.begin(), ::toupper);
// getline()
// For any integer n, the bitwise complement of n will be - (n + 1).
// Left shift operator (<<): It takes two numbers, the left shift operator
// shifts the bits of the first operand, the second operand decides the number
// of places to shift.
// Left shift means appending numbers of 0’s to the right.
// Right shift means remove numbers of 0’s from right 1 0 = 2
// cout << "Size of double : " << sizeof(double) << "\n";
// cout << "Size of a : " << sizeof(a) << "\n";
// int x, y;
// y = 100;
// x = (y + 10, 99 + y);
// cout << "With brackets value of x :" << x << endl;
// x = y + 10, 99 + y;
// cout << "Without brackets value of x :" << x;
// return 0;
// }
// Output:
// With brackets value of x :199
// Without brackets value of x :110
// Conditional Operator(?:) or ternary operators: It is of the form
// Expression1 ? Expression2 : Expression3
// Here, Expression1 is the condition to be evaluated. If the
// condition(Expression1) is True, then we will execute and return the result of
// Expression2; otherwise, if the condition(Expression1) is false, then we will
// execute and return the result of Expression3. Since it takes three operands
// to work, hence they are also called ternary operators.
// int a = 1, * b; //Here b is a pointer operator of int type
// b = & a;
// cout << "Address of variable a: " << b << endl;
// cout << "Address of variable b: " << & b;
// break
// continue
// goto:
int number;
cin >> number;
if (number % 2 == 0)
goto printeven;
else
goto printodd;
printeven : cout << "Even number";
return 0;
printodd : cout << "Odd number";
return 0;
// return
// int arr[]{40, 50, 60, 70, 80, 90, 100};
// for (auto element : arr)
// cout << element << " ";
#include <algorithm>
#include <iostream>
using namespace std;
int print_even(int n) {
if (n % 2 == 0)
cout << n << ' ';
}
int main() {
int arr[5] = {1, 2, 3, 4, 5};
cout << "The Array contains the following even numbers" << endl;
for_each(arr, arr + 5, print_even);
return 0;
}
// stl c++
vector<int>::iterator m = nums.begin(); // m will mark the virtual "S.end()".
for (int &val : nums) {
auto it = lower_bound(nums.begin(), m, val);
*it = val;
if (it == m)
m++;
}
// get random element from the vector
int getRandom() {
// rand() function gives random value in the range of 0 to RAND_MAX(whose
// value is 32767). x%y gives remainder when x is divided by y and this
// remainder is in the range of 0 to y-1. rand()%a.size() gives random value
// in the range of (0 to a.size()-1). a[rand()%a.size()] will give random
// value of array in the range of a[0] to a[a.size()-1].
return a[rand() % a.size()];
}