Escrito por kaioken
viernes 17 de junio del 2005 @ 12:37 AM
4. Desarrolle los algoritmos correspondientes:
a) Multiplicación de los primeros 100 numeros primos.
La raiz cuadrada de un numero.
c) El mayor de tres numeros.
d) La calificacion de 5 estudiantes para 4 asignaturas de 3 puntuaciones
a)
Codigo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
<?php
public class Primos {
public static void main(String[] args)
{
Primos $primo = new Primos();
int $resultado = 1;
for (int i = 1; i <= 100; i++)
{
if($primo.setPrimos(i))
{
$resultado = i * i;
}
}
System.out.println($resultado);
}
public boolean setPrimos(int $number)
{
for(int i = 2; i <= $number / 2; i++)
{
if($number % i == 0)
{
return false;
}
}
return true;
}
}
?>
|
Codigo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
<?php
public class Raiz
{
public static void main(String[] args)
{
//numero a el que se le va a buscar la raiz cuadrada
double raiz = 25;
double newraiz = raiz / 2;
double oldraiz;
do
{ oldraiz = newraiz;
newraiz = (oldraiz + raiz / oldraiz) / 2;
System.out.println(newraiz);
}
while (Math.abs(newraiz - oldraiz) > 1E-4);
}
}
?>
|
c)
Codigo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
<?php
public class Mayor {
public static void main(String[] args)
{
int $a,$b,$c;
$a = 1;
$b = 7;
$c = 5;
Mayor $big = new Mayor();
int $mayor1 = $big.setMayor($a, $b);
int $mayor2 = $big.setMayor($mayor1, $c);
System.out.println($mayor2);
}
public int setMayor(int $a, int $b)
{
if ($a > $b)
{
$b = $a;
}
return $b;
}
}
?>
|
d)
Codigo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
<?php
public class Grade {
public static void main(String[] args)
{
String[] $estudiantes = {"Max", "Naruto", "Sasuke", "Rukawa", "Sakuragi"};
String[] $materias = {"Prog Web", "Deporte", "Jutsu", "Arte"};
String[] $notas = {"AAFF", "FFAF", "AAAA", "AAAA", "FAFF"};
System.out.println("(Asignaturas Del Semestre)");
for(int j = 0; j < $materias.length; j++)
{
System.out.print($materias[j] +" - ");
}
System.out.println("\n");
for (int i = 0; i < $estudiantes.length; i++)
{
System.out.println(""+$estudiantes<i>+" - "+$notas<i> ;
}
}
}
?>
|
Codigo:
<?phpdfadf
if()
{
}
?>
nose
d
f
df
ad
f
nose coóodfodofo