Más código
Hace cerca de un mes que me inscribí en la web de project euler, dónde existen muchos problemas matemáticos los cuales debemos darles solución con un algoritmo, sea en el elnguaje que sea.
Dejo algunos que he resuelto:
#include <stdio.h>
main()
{
printf(“Problema 05\n”);
register int i=1;
int j=2520;
int tmp=1;
int resultado=0;
while(j>0)
{
i=1;
tmp=i;
while(i<=20)
{
resultado=j%i;
if(resultado==0)
{
tmp++;if(tmp==20)
{
printf(“j: %d i: %d tmp: %d\n”, j, i, tmp);
break;
}}
else
{
break;
}
i++;
}
if(tmp==20)
{
break;
}
j++;
}}
Problema 5
/*
The sum of the squares of the first ten natural numbers is,
12 + 22 + … + 102 = 385The square of the sum of the first ten natural numbers is,
(1 + 2 + … + 10)2 = 552 = 3025Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
*/#include <stdio.h>
#include <math.h>main()
{
double res=0;
int i=0;
double tmp=0;
double tmp2=0;
while(i<=100)
{res=pow(i, 2);
tmp+=res;
printf(“El cuadrado es: %f, la sumatoria es: %f\n”, res, tmp);
tmp2+=i;
if(i==100)
{
tmp2=pow(tmp2, 2);
printf(“La sumatoria dos es %f\n”, tmp2);
double fin = tmp2-tmp;
printf(“Final: %f\n”, fin);
}
i++;
}}
Problema 6…
No es la gran cosa, pero me entetienen bastante
saludos
Comando tee
Hace tiempo que leí acerca del comando tee de los sistemas operativos tipos Unix, y he olvidado probarlo hasta hoy que se lo pregunté a Vicente y después Dante me clarificó un poco. Creo que no supe plantear bien la pregunta, y por eso obtuve una respuesta poco exacta.
El manual en linea de Linux nos dice:
TEE(1) User Commands TEE(1)
NAME
tee – read from standard input and write to standard output and files
SYNOPSIS
tee [OPTION]… [FILE]…
DESCRIPTION
Copy standard input to each FILE, and also to standard output.
-a, –append
append to the given FILEs, do not overwrite
-i, –ignore-interrupts
ignore interrupt signals
–help display this help and exit
–version
output version information and exit
If a FILE is -, copy again to standard output.
AUTHOR
Written by Mike Parker, Richard M. Stallman, and David MacKenzie.
REPORTING BUGS
Report bugs to .
COPYRIGHT
Copyright © 2008 Free Software Foundation, Inc. License GPLv3+: GNU
GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
The full documentation for tee is maintained as a Texinfo manual. If
the info and tee programs are properly installed at your site, the com�
mand
info coreutils â€â€™tee invocationâ€â€™
should give you access to the complete manual.
GNU coreutils 6.10 April 2008 TEE(1)
Bien, veamos que pasa con la siguiente secuencia de comandos:
$rodrigo@rodrigo:~$ date; who | wc
mié nov 5 01:44:03 CST 2008
3 15 136
Esto nos refleja que solo la salida de el comando who fue al comando wc, esto es porque el pipe (|) es de mayor precedencia que la del ;
Esto es fácil de solucionar si usamos los maravillosos paréntesis:
rodrigo@rodrigo:~$ (date; who) | wc
3 16 120
El flujo de datos a través de un pipe puede ser estraído y colocado en un archivo (pero no en otra interconexión) por medio del comando tee, que no es parte del shell, poro es muy útil para manipular las interconexiones, uno de sus usos es almacenar la salida intermedia en un archivo:
rodrigo@rodrigo:~$ (date; who) | tee archivo | wc
3 16 120
Muestra en la salida el comando como anteriormente lo vimos y además las salidas de los comandos las almacena en “archivo”:
rodrigo@rodrigo:~$ more archivo
mié nov 5 01:49:49 CST 2008
rodrigo tty7 2008-11-04 22:32 (:0)
rodrigo pts/2 2008-11-05 01:43 (:0.0)
tee copia su entrada al archivo o archivos indicados, así como su salida; de este modo wc (word counter) recibe la misma información que recibiría si tee no estuviera en la interconexión.
Mi duda es cómo sería su equivalente sin usar el comando tee.
Espero que me hayan entendido y si tienen alguna aportación muchas gracias desde ya
return lyonn
Hola, de verdad me da mucho gusto regresar a administrar este sito, ya que cuando lo administré no pensé que le sirviera a alguien. Espero seguir con este sitio y con sus motivos (subir códigos en C)….
Bueno, es mucho blablabla, mejor me pongo a trabajar, pronto subiré algunos códigos
Viendo de nuevo este sitio, me he acordado de un editor de texto que estaba haciendo hace ya tiempo, pero que se perdió con mi OpenSolaris, así que retomaré ese proyecto y le volveré a invertir un poco de tiempo
saludos y gracias
-
Recientes
-
Enlaces