Przeglądaj źródła

Ejercios de factorial y pascal

master
Griezman2003 1 rok temu
rodzic
commit
37ad8c1913
5 zmienionych plików z 133 dodań i 2 usunięć
  1. +51
    -0
      app/Commands/Factorial.php
  2. +80
    -0
      app/Commands/Pascal.php
  3. +1
    -1
      composer.json
  4. +1
    -1
      config/app.php
  5. +0
    -0
      ejercicios

+ 51
- 0
app/Commands/Factorial.php Wyświetl plik

@@ -0,0 +1,51 @@
<?php

namespace App\Commands;

use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;

class Factorial extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'factorial';

/**
* The description of the command.
*
* @var string
*/
protected $description = 'este comando es para calcular el factorial de un numero';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$num=10;
$fact=1;
for ($i = $num; $i > 0; $i--)
{
$fact= $fact * $i;
}
echo "El numero factorial es el siguiente = ".$fact;

}

/**
* Define the command's schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
public function schedule(Schedule $schedule): void
{
// $schedule->command(static::class)->everyMinute();
}
}

+ 80
- 0
app/Commands/Pascal.php Wyświetl plik

@@ -0,0 +1,80 @@
<?php

namespace App\Commands;

use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;

class Pascal extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'pascal';

/**
* The description of the command.
*
* @var string
*/
protected $description = 'Comando que describe el proceso de pascal';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
function generarPiramidePascal($filas) {
$triangulo = array();
for ($i = 0; $i < $filas; $i++) {
$triangulo[$i] = array();
$triangulo[$i][0] = 1;
for ($gama = 1; $gama < $i; $gama++) {
$triangulo[$i][$gama] = $triangulo[$i-1][$gama-1] + $triangulo[$i-1][$gama];
}
$triangulo[$i][$i] = 1;
}
return $triangulo;
}
function mostrarPiramidePascal($triangulo) {
$filas = count($triangulo);
for ($i = 0; $i < $filas; $i++) {
$espacios = str_repeat(" ", $filas - $i);
echo $espacios;
for ($gama = 0; $gama <= $i; $gama++) {
echo $triangulo[$i][$gama] . " ";
}
echo "\n";
}
}
$numeroFilas = 10;
$piramide = generarPiramidePascal($numeroFilas);
mostrarPiramidePascal($piramide);
}

/**
* Define the command's schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
public function schedule(Schedule $schedule): void
{
// $schedule->command(static::class)->everyMinute();
}
}

+ 1
- 1
composer.json Wyświetl plik

@@ -47,5 +47,5 @@
},
"minimum-stability": "stable",
"prefer-stable": true,
"bin": ["application"]
"bin": ["ejercicios"]
}

+ 1
- 1
config/app.php Wyświetl plik

@@ -13,7 +13,7 @@ return [
|
*/

'name' => 'Application',
'name' => 'Ejercicios',

/*
|--------------------------------------------------------------------------


application → ejercicios Wyświetl plik


Ładowanie…
Anuluj
Zapisz