Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

-1int maxSubArraySum(int a[], int size)

{
int max_so_far = INT_MIN, max_ending_here = 0;

for (int i = 0; i < size; i++) {


max_ending_here = max_ending_here + a[i];
if (max_so_far < max_ending_here)
max_so_far = max_ending_here;

if (max_ending_here < 0)
max_ending_here = 0;
}
return max_so_far;
}
‫عشان ال‬maximum sum of array

-2 bool cmp(const pair<int,int> &a,

const pair<int,int> &b)


{
return (a.second < b.second);
}

3-void decToBinary(int n)

{
// array to store binary number
int binaryNum[32];

// counter for binary array


int i = 0;
while (n > 0) {

// storing remainder in binary array


binaryNum[i] = n % 2;
n = n / 2;
i++;
}

// printing binary array in reverse order


for (int j = i - 1; j >= 0; j--)
cout << binaryNum[j];
}
4-int bintodec(long long n) {
int dec = 0, i = 0, rem;

while (n!=0) {
rem = n % 10;
n /= 10;
dec += rem * pow(2, i);
++i;
}

return dec;
}

You might also like