Algunas funciones útiles: C y C++
Algunas de las funciones son muy facilitas, otras no tanto y algunas seguramente nunca las utilices, pero están bien para aprender o usar en algunos proyectos.
int MCD( const int a, const int b )
{
int m = (a<b?a:b); // min(a,b)
while ( ( a % m != 0) || (b % m != 0 ) ) m--;
return m;
}
int MCM( const int a, const int b )
{
int m = (a>b?a:b); // max(a,b)
while ( ( m % a != 0) || (m % b != 0 ) ) m++;
return m;
}
int min( const int a, const int b )
{
return ( a < b ? a : b);
}
int max( const int a, const int b )
{
return ( a > b ? a : b);
}
int abs( const int a)
{
return ( a < 0 ? -a : a);
}
typedef unsigned long long BIG;
BIG pow( const int a, int b)
{
unsigned int n = 1;
while(b--) n *= a;
return n;
}
BIG factorial(unsigned int n)
{
if (n <= 1) return 1;
for(int i=n-1; i>1 ;i--)
n = n * i;
return n;
}
BIG fibonacci(unsigned int n)
{
BIG r, t0=0, t1=1;
if(n == 0) return 0;
if(n == 1) return 1;
for(int i=1; i<n; i++)
{
r = t0+t1;
t0 = t1;
t1 = r;
}
return r;
}
const double PI = 3.14159265358979323846;
double rad2deg(double rad)
{
return (180.0 * rad / PI);
}
double deg2rad(double deg)
{
return (PI * deg / 180.0);
}
unsigned long rgb2hex(const int r,const int g,const int b)
{
return (unsigned long)(r | g<<8 | b<<16);
}
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
#define RGB(r,g,b)((DWORD)(((BYTE)(r)|((WORD)(g)<<8))|(((DWORD)(BYTE)(b))<<16)))
#define R(c) ( (BYTE) ( (DWORD)(c) & (DWORD)(0xff) ) )
#define G(c) ( (BYTE) ( ((DWORD)(c) & (DWORD)(0xff00)) >> 8) )
#define B(c) ( (BYTE) ( ((DWORD)(c) & (DWORD)(0xff0000)) >> 16) )
wua asta k veo algo bueno en internet gracia bro por el aporte ....stack...
ResponderEliminar