Programacion

Páginas: 68 (16797 palabras) Publicado: 5 de febrero de 2013
///**************************************************************************///
///***************************** NATURALES ******************************///
///**************************************************************************///

//------------------------------------------------------------------------------
// 1) PROGRAMA QUE MUESTRA LOS PRIMEROS N NÚMEROS NATURALES //
voidMostrar( byte n ) {
if ( n == 0 ) {
}
else {
Mostrar( n - 1 );
ShowMessage( n );
}
}
//------------------------------------------------------------------------------
// 2) PROGRAMA QUE MUESTRA LOS PRIMEROS N NÚMEROS NATURALES INVERTIDOS //
void Mostrar1( byte n ) {
if ( n == 0 ) {
}
else {
ShowMessage( n );
Mostrar1( n - 1 );
}
}//------------------------------------------------------------------------------
// 3) PROGRAMA QUE MUESTRA LOS PRIMEROS N NÚMEROS PARES //
void MostrarPares( byte n ) {
if ( n == 0 ) {
}
else {
MostrarPares( n - 1 );
ShowMessage( n * 2 - 2 );
}
}
//------------------------------------------------------------------------------
// 4) PROGRAMA QUE ELIMINA LOS DÍGITOS PARES DE UN NÚMERO //void EliminarPares( Cardinal &n ) {
if ( n < 10 ) {
if ( n % 2 == 0 )
n = 0;
}
else {
byte d;
d = n % 10;
n = n / 10;
EliminarPares( n );
if ( d % 2 == 1 )
n = n * 10 + d;
}
}
//------------------------------------------------------------------------------
// 5) PROGRAMA QUE MUESTRA LA SUMA DE LOS DÍGITOS PARES DE UN NÚMERO //
byteSumaDigitosPares( Cardinal x ) {
byte sum;
if ( x < 10 ) {
if ( x % 2 == 0 )
sum = x;
else
sum = 0;
}
else {
sum = SumaDigitosPares( x / 10 );
if ( ( ( x % 10 ) % 2 ) == 0 )
sum = sum + ( x % 10 );
}
return ( sum );
}
//------------------------------------------------------------------------------
// 6) PROGRAMA QUE MUESTRA LACANTIDAD DE DÍGITOS PARES DE UN NÚMERO //
byte CantidadPar( Cardinal x ) {
byte c;
if ( x < 10 ) {
if ( x % 2 == 0 )
c = 1;
else
c = 0;
}
else {
c = CantidadPar( x / 10 );
if ( x % 2 == 0 )
c++;
}
return ( c );
}
//------------------------------------------------------------------------------
// 7) PROGRAMA QUE MUESTRA LOS PRIMEROS NNÚMEROS IMPARES //
void MostrarImpares( byte n ) {
if ( n == 0 ) {
}
else {
MostrarImpares( n - 1 );
ShowMessage( n * 2 - 1 );
}
}
//------------------------------------------------------------------------------
// 8) PROGRAMA QUE ELIMINA LOS DÍGITOS IMPARES DE UN NÚMERO //
void elimImpares( Cardinal &n ) {
if ( n < 10 ) {
if ( n % 2 == 1 )
n = 0;
}else {
byte d;
d = n % 10;
n = n / 10;
elimImpares( n );
if ( ( d % 2 ) == 0 )
n = n * 10 + d;
}
}
//------------------------------------------------------------------------------
// 9) PROGRAMA QUE MUESTRA LA SUMA DE LOS DÍGITOS IMPARES DE UN NÚMERO //
/*byte SumaDigitosImpares( Cardinal x ) {
byte sum;
if ( x < 10 ) {
if ( x % 2 == 1 )sum = x;
else
sum = 0;
}
else {
sum = SumaDigitosImpares( x / 10 );
if ( ( ( x % 10 ) % 2 ) == 1 )
sum = sum + ( x % 10 );
}
return ( sum );
}*/
//------------------------------------------------------------------------------
// 10) PROGRAMA QUE MUESTRA LA CANTIDAD DE DÍGITOS IMPARES DE UN NÚMERO //
/*byte CantidadImpar( Cardinal x ) {
byte c;if ( x < 10 ) {
if ( x % 2 == 1 )
c = 1;
else
c = 0;
}
else {
c = CantidadImpar( x / 10 );
if ( x % 2 == 1 )
c++;
}
return ( c );
}*/
//------------------------------------------------------------------------------
// 11) PROGRAMA QUE MUESTRA LA SUMA DE LOS DÍGITOS DE UN NÚMERO //
byte SumaDigitos( Cardinal n ) {
byte s;
if ( n...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Programación
  • Programacion
  • Programacion
  • Programación
  • Programacion
  • Programacion
  • Programacion
  • Programacion

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS