Sunteți pe pagina 1din 14

tream>

#include <cmath>

using namespace std;

#define MAX_ARRAY_LENGTH 100

unsigned int computeDigitSum(unsigned int number){


int s = 0;
int c;
while (number != 0)
{
c = number % 10;
s = s + c;
number = number % 10;
number = number / 10;
}
return s;
}
void main()
{
cout << "computerDigitSum(123)";
system("pause");
}

#include <iostream>
#include <cmath>
using namespace std;

#define MAX_ARRAY_LENGTH 100

bool isLeap(unsigned int year){


if ((year % 4 == 0 || year % 100 == 1) && (year % 400 == 0)) return 1;
else return 0;
}

#include <iostream>
#include <cmath>
using namespace std;

#define MAX_ARRAY_LENGTH 100


bool isPalindrome(int number){
int aux=0;
int copy = number;
while (number)
{
aux = aux * 10 + number % 10;
number = number / 10;

}
if (copy == aux) return true;

else return false;

}
#include <iostream>
#include <cmath>

using namespace std;

#define MAX_ARRAY_LENGTH 100


unsigned int computeNumberOfDays(unsigned int year, unsigned int month){

if ((month == 2) && (isLeap(year) == 1))


return 29;
else if (month == 2)
return 28;
if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8)
|| (month == 10) || (month == 12))
return 31;
else return 30;

}
#include <iostream>
#include <cmath>
using namespace std;

#define MAX_ARRAY_LENGTH 100

unsigned int computeControlDigit(unsigned int number) {

if (number % 9 == 0)
return 9;
else return number % 9;
}
#include <iostream>
#include <cmath>

using namespace std;

#define MAX_ARRAY_LENGTH 100


struct vector
{
unsigned int length;
int values[MAX_ARRAY_LENGTH];
};
vector getPerfects(unsigned int upperLimit);
bool isPerfect(unsigned int number) {
int sum = 1,i;
for ( i = 2;i <=(number)/ 2; i++)
{
sum = sum + 1;
}
if (sum == number)
return 1;
return 0;
}

#include <iostream>
#include <cmath>
using namespace std;

#define MAX_ARRAY_LENGTH 100


bool isPrime(int number) {
int d;
if (number = 1)
return 0;

else
for (d = 2; d <=sqrt(number)/2; d++)
if (number%d == 0)
return 0;
return 1;
}

#include <iostream>
#include <cmath>
using namespace std;

#define MAX_ARRAY_LENGTH 100

struct matrix
{
unsigned int lines;
unsigned int columns;
int values[MAX_ARRAY_LENGTH][MAX_ARRAY_LENGTH];
};
bool areTwinPrimes(unsigned int number1, unsigned int number2){
int k = 3, i = 1;
int n;
while (i <= n)
{
if (isPrime(number1) == 1 && isPrime(number2) == 1) return 1;
i = i + 1;
k = k + 2;
}
return 0;

#include <iostream>
#include <cmath>
using namespace std;
;
#define MAX_ARRAY_LENGTH 100
struct vector
{
unsigned int length;
int values[MAX_ARRAY_LENGTH];
};
unsigned int getMaxDifference(vector v){
int i, mini, max;
max = mini = v.values[0];
for (i = 1; i <= v.length[i]; i++)
if (v.values[i] > max)max = v.values[i];
else if (v.values[i], mini)mini = v.values[i];
return max - mini;
}
#include <iostream>
#include <cmath>
using namespace std;

#define MAX_ARRAY_LENGTH 100


struct sequence
{
unsigned int startPosition;
unsigned int length;

};
struct vector
{
unsigned int length;
int values[MAX_ARRAY_LENGTH];
};
sequence getMaxSequence(vector v) {
sequence summaxSequence;
summaxSequence.startPosition = 0;
summaxSequence.length = 1;

int m,n, summax = 0, sum;


for (m = 0; m < v.length - 1; m++)
{
sum = v.values[m];
for (n = m + 1; n < v.length; n++)
{
sum = sum + v.values[n];
if (sum > summax)
{
summax = sum;
summaxSequence.startPosition = m;
summaxSequence.length = n - m + 1;

}
}
}
#include <iostream>
#include <cmath>

using namespace std;

#define MAX_ARRAY_LENGTH 100


struct sequence
{
unsigned int startPosition;
unsigned int length;
};
struct vector
{
unsigned int length;
int values[MAX_ARRAY_LENGTH];
};
sequence getMaxSumSequence(vector v);
{
int k, i, j, s = 0, smax = v.values[0], sequence ss;
for (i = 0; i < v.lenght; i++)
for (j = 1; j < v.lenght; j++)
for (k = i; k <= j; k++)
s = s + v.values[k];
if (s > smax) {
ss.starposition = i;
ss.lenght = k;
}
return ss;
}
#include <iostream>
#include <cmath>
using namespace std;

#define MAX_ARRAY_LENGTH 100


struct vector
{
unsigned int length;
int values[MAX_ARRAY_LENGTH];
};
vector orderElements(vector v);
{
int vectoraux[100], pos = 0, m;
for (m = 0; m < v.length; m++)
vectoraux[m] = v.values[m];
for (m = 0; m < v.length; m++)
if (vectoraux[m] % 2 == 0)
{
v.values[pos] = vectoraux[m];
pos++;
}
for (m = 0; m < v.length; m++)
if (vectoraux[m] % 2 != 0)
{
v.values[pos] = vectoraux[m];
pos++;
}
return vector v;
}
#include <iostream>
#include <cmath>
using namespace std;

#define MAX_ARRAY_LENGTH 100


struct vector
{
unsigned int length;
int values[MAX_ARRAY_LENGTH];
};
bool containsMajorElement(vector v);
{
int i, j, aparitii;
for (i = 0; i < v.length; i++)
{
aparitii = 0;
for (j = 0; j < v.length; j++)
if (v.values[i] == v.values[j])
aparitii++;
if (aparitii > v.length / 2) return true;
}
return false;

#include <iostream>
#include <cmath>
using namespace std;

#define MAX_ARRAY_LENGTH 100


struct matrix
{

unsigned int lines;


unsigned int columns;
int values[MAX_ARRAY_LENGTH][MAX_ARRAY_LENGTH];
};

matrix sortDiagonalElements(matrix m);


{int i, j, x, z, aux;
for (i = 0; i < m.lines - 1; i++)
for (j = i + 1; j < m.lines; j++)
if (m.values[i][i] < m.values[j][j])
{
for (x = 0; x < m.lines; x++)
{
aux = m.values[x][j];
m.values[x][j] = m.values[x][i];
m.values[x][i] = aux;
}
for (x = 0; x < m.columns; x++)
{
aux = m.values[j][x];
m.values[j][x] = m.values[i][x];
m.values[i][x] = aux;
}
}
return m;
}

#include <iostream>

#include <cmath>

using namespace std;

#define MAX_ARRAY_LENGTH 100


vector getSpiralVector(matrix m);
{
vector v;
int n, i, j, k, x;
x = 1;
for (k = 1; k <= (n + 1) / 2; k++)
{
for (j = k; j <= n + 1 - k; j++) m.values[k][j] = x++;
for (i = k + 1; i < n + 1 - k; i++) m.values[i][n + 1 - k] = x+
+;
for (j = n - k; j >= k; j--) m.values[n + 1 - k][j] = x++;
for (i = n - k; i >= k + 1; i--) m.values[i][k] = x++;
}
for (i = 1; i <= n:i++)
{
for (j = 1; j <= n; j++)
cout << endl;
}

}
#include <iostream>
#include <cmath>
using namespace std;

#define MAX_ARRAY_LENGTH 100


date getNextDate(date currentDate);
{date getNextDate(date currentDate)
{
if (currentDate.day == 31 && currentDate.month == 12) {
currentDate.day = 1;
currentDate.month = 1;
currentDate.year = currentDate.year + 1;
}
else if (currentDate.day <
computeNumberOfDays(currentDate.year, currentDate.month))
{
currentDate.day = currentDate.day + 1;
}
else if (currentDate.day ==
computeNumberOfDays(currentDate.year, currentDate.month))
{
currentDate.day = 1;
currentDate.month = currentDate.month + 1;
}
return currentDate;
}

equation computeEquation(point point1, point point2)


{
equation dreapta;
dreapta.a = point2.y - point1.y;
dreapta.b = (-1)*(point2.x - point1.x);
dreapta.c = point1.y * point2.x - point1.x * point2.y;

return dreapta;
}

S-ar putea să vă placă și