miércoles, 3 de febrero de 2016
REINICIAR BLACBERRY 8520 SIN SACAR LA BATERÍA DESDE EL TECLADO.
Por ciertos motivos hay veces que tenemos que reiniciar nuestro dispositivo blackberry, como por ejemplo: el funcionamiento de ciertas aplicaciones que necesitan usar paquetes de datos o conexión WIFI y después de cierto tiempo pierden conexión entonces es necesario reiniciar el dispositivo para que estas aplicaciones vuelvan a funcionar correctamente.
Es tedioso sacara la batería y volverla a poner para que el dispositivo se reinicie, por esta razón les presento una manera mas cómoda de reiniciar el dispositivo en este caso es el blackberry 8520.
Es tedioso sacara la batería y volverla a poner para que el dispositivo se reinicie, por esta razón les presento una manera mas cómoda de reiniciar el dispositivo en este caso es el blackberry 8520.
1. Presionamos y mantenemos presionada la tecla Alt que se encuentra en el lado izquierdo-inferior. Ej:
2. Luego presionamos y mantenemos presionada la tecla Mayúsculas de la derecha-inferior. Ej:
3. Posteriormente presionamos y mantenemos la tecla de retroceso/eliminar "del". Ej:
4. Finalmente dejamos de presionar las tres teclas mencionadas anteriormente.
5. Y por ultimo presionamos nuevamente la tecla alt, la misma que presionamos al principio. Ej:
5. Si presionaron las teclas en el orden correcto el dispositivo empezara a reiniciare automáticamente, solo esperamos a que realice el proceso de reinicio y vuelva a encender por si solo.
miércoles, 2 de septiembre de 2015
Ejemplo de script completo en Brazilfw
#!/bin/bash
# Configure Iptables for Firewalling and NAT
echo " #######################################"
echo " # Enabling Firewall #"
echo " #######################################"
### Location of the iptables and kernel module programs
IPTABLES=/sbin/iptables
#IPTABLES=/usr/local/sbin/iptables
### declaring interfaces
INET='ppp0'
LAN='eth0'
# disable forwarding - done for security - enabled at the end
echo " - Disabling forwarding (security).."
echo "0" > /proc/sys/net/ipv4/ip_forward
echo " - Enabling DynamicAddr.."
echo "1" > /proc/sys/net/ipv4/ip_dynaddr
### Clearing previous rules and setting default policy ###
echo "Clearing previous rules and setting default policy..."
$IPTABLES -F INPUT
$IPTABLES -P INPUT DROP
$IPTABLES -F OUTPUT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F FORWARD
$IPTABLES -P FORWARD DROP
$IPTABLES -t nat -F
### Clearing previous rules and setting default policy END ###
### FORWARD ###
echo "Enabling Forwarding..."
# FORWARD: Allow all connections OUT and only existing and related ones IN..
$IPTABLES -A FORWARD -i $INET -o $LAN -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $LAN -o $INET -j ACCEPT
### FORWARD END ###
### NAT ###
echo "Enabling Nat..."
echo " - Enabling SNAT (MASQUERADE) functionality on internet interface.."
$IPTABLES -t nat -A POSTROUTING -o $INET -j MASQUERADE
### NAT END ###
### General INPUT ###
echo "Enabling General INPUT rules..."
$IPTABLES -A INPUT -i $LAN -m state --state RELATED,ESTABLISHED -j ACCEPT # allow incomming replys on outgoing lan traffic
$IPTABLES -A INPUT -i $INET -m state --state RELATED,ESTABLISHED -j ACCEPT # allow incomming replys on outgoing internet traffic
### General INPUT END ###
### Localhost ###
echo "Localhost rules..."
$IPTABLES -A INPUT -i lo -j ACCEPT # allow all incomming traffic on localhost
$IPTABLES -A OUTPUT -o lo -j ACCEPT # allow all outgoing traffic on localhost
### Localhost END ###
### ICMP ###
echo "ICMP rules..."
$IPTABLES -A INPUT -p icmp -m state --state RELATED,ESTABLISHED -j ACCEPT # allow replys on outgoing icmp traffic
$IPTABLES -A INPUT -i $LAN -p icmp --icmp-type 8 -m limit --limit 1/sec -j ACCEPT # allow echo request comming from lan
$IPTABLES -A INPUT -p icmp -j LOG --log-prefix "All other icmp:" # log all other icmp traffic
### ICMP END ###
### Samba ###
echo "Samba rules..."
$IPTABLES -A INPUT -i $LAN -p tcp --dport 137 -j ACCEPT # NetBIOS name service tcp
$IPTABLES -A INPUT -i $LAN -p udp --dport 137 -j ACCEPT # NetBIOS name service udp
$IPTABLES -A INPUT -i $LAN -p udp --dport 138 -j ACCEPT # NetBIOS datagram service
$IPTABLES -A INPUT -i $LAN -p tcp --dport 139 -j ACCEPT # NetBIOS session service File/printer sharing and other operations
$IPTABLES -A INPUT -i $LAN -p tcp --dport 445 -j ACCEPT # Used by Win2k/xp when NetBIOS over TCP/IP is disabled - Microsoft Common Internet File System
$IPTABLES -A INPUT -i $LAN -p udp --dport 445 -j ACCEPT
#$IPTABLES -A INPUT -i $LAN -p tcp --dport 901 -j ACCEPT # used by SWAT (GUI configuration tool for samba)
### Samba END ###
### SSH ###
echo "SSH rules..."
$IPTABLES -A INPUT -i $LAN -p tcp --dport 22 -j ACCEPT # allow ssh connections from lan
### SSH END ###
### Webserver ###
echo "Webserver rules..."
$IPTABLES -A INPUT -i $LAN -p tcp --dport 80 -j ACCEPT # Open Webserver to lan
### Webserver END ###
### DNAT eMULE ###
echo "DNAT eMule..."
$IPTABLES -A FORWARD -j ACCEPT -p tcp --dport 4545
$IPTABLES -t nat -A PREROUTING -i $INET -p tcp --dport 4545 -j DNAT --to 192.168.0.1:4545
$IPTABLES -A FORWARD -j ACCEPT -p udp --dport 4646
$IPTABLES -t nat -A PREROUTING -i $INET -p udp --dport 4646 -j DNAT --to 192.168.0.1:4646
$IPTABLES -A FORWARD -j ACCEPT -p tcp --dport 4661
$IPTABLES -t nat -A PREROUTING -i $INET -p tcp --dport 4661 -j DNAT --to 192.168.0.1:4661
$IPTABLES -A FORWARD -j ACCEPT -p udp --dport 4672
$IPTABLES -t nat -A PREROUTING -i $INET -p udp --dport 4672 -j DNAT --to 192.168.0.1:4672
$IPTABLES -A FORWARD -j ACCEPT -p tcp --dport 4662
$IPTABLES -t nat -A PREROUTING -i $INET -p tcp --dport 4662 -j DNAT --to 192.168.0.1:4662
$IPTABLES -A FORWARD -j ACCEPT -p tcp --dport 4771
$IPTABLES -t nat -A PREROUTING -i $INET -p tcp --dport 4771 -j DNAT --to 192.168.0.1:4771
$IPTABLES -A FORWARD -j ACCEPT -p tcp --dport 3306
$IPTABLES -t nat -A PREROUTING -i $INET -p tcp --dport 3306 -j DNAT --to 192.168.0.1:3306
### DNAT eMULE END ###
# block all outgoing traffic to the internet from port 0:1024
$IPTABLES -A OUTPUT -o $INET -p tcp --sport 1:1024 -j DROP
$IPTABLES -A OUTPUT -o $INET -p udp --sport 1:1024 -j DROP
$IPTABLES -A INPUT -i $INET -j LOG # Log all other input from internet
$IPTABLES -A FORWARD -j LOG --log-prefix "Forward:" # Log all other forward
$IPTABLES -A INPUT -i $LAN -j LOG --log-prefix "from LAN:" # log all other input form lan
# enable forwarding - done last for security
echo " - Enabling forwarding.."
echo "1" > /proc/sys/net/ipv4/ip_forward
# saving iptables rules (works for Redhat/Fedora) (perhaps other distributions too)
/sbin/iptables-save
# Configure Iptables for Firewalling and NAT
echo " #######################################"
echo " # Enabling Firewall #"
echo " #######################################"
### Location of the iptables and kernel module programs
IPTABLES=/sbin/iptables
#IPTABLES=/usr/local/sbin/iptables
### declaring interfaces
INET='ppp0'
LAN='eth0'
# disable forwarding - done for security - enabled at the end
echo " - Disabling forwarding (security).."
echo "0" > /proc/sys/net/ipv4/ip_forward
echo " - Enabling DynamicAddr.."
echo "1" > /proc/sys/net/ipv4/ip_dynaddr
### Clearing previous rules and setting default policy ###
echo "Clearing previous rules and setting default policy..."
$IPTABLES -F INPUT
$IPTABLES -P INPUT DROP
$IPTABLES -F OUTPUT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F FORWARD
$IPTABLES -P FORWARD DROP
$IPTABLES -t nat -F
### Clearing previous rules and setting default policy END ###
### FORWARD ###
echo "Enabling Forwarding..."
# FORWARD: Allow all connections OUT and only existing and related ones IN..
$IPTABLES -A FORWARD -i $INET -o $LAN -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $LAN -o $INET -j ACCEPT
### FORWARD END ###
### NAT ###
echo "Enabling Nat..."
echo " - Enabling SNAT (MASQUERADE) functionality on internet interface.."
$IPTABLES -t nat -A POSTROUTING -o $INET -j MASQUERADE
### NAT END ###
### General INPUT ###
echo "Enabling General INPUT rules..."
$IPTABLES -A INPUT -i $LAN -m state --state RELATED,ESTABLISHED -j ACCEPT # allow incomming replys on outgoing lan traffic
$IPTABLES -A INPUT -i $INET -m state --state RELATED,ESTABLISHED -j ACCEPT # allow incomming replys on outgoing internet traffic
### General INPUT END ###
### Localhost ###
echo "Localhost rules..."
$IPTABLES -A INPUT -i lo -j ACCEPT # allow all incomming traffic on localhost
$IPTABLES -A OUTPUT -o lo -j ACCEPT # allow all outgoing traffic on localhost
### Localhost END ###
### ICMP ###
echo "ICMP rules..."
$IPTABLES -A INPUT -p icmp -m state --state RELATED,ESTABLISHED -j ACCEPT # allow replys on outgoing icmp traffic
$IPTABLES -A INPUT -i $LAN -p icmp --icmp-type 8 -m limit --limit 1/sec -j ACCEPT # allow echo request comming from lan
$IPTABLES -A INPUT -p icmp -j LOG --log-prefix "All other icmp:" # log all other icmp traffic
### ICMP END ###
### Samba ###
echo "Samba rules..."
$IPTABLES -A INPUT -i $LAN -p tcp --dport 137 -j ACCEPT # NetBIOS name service tcp
$IPTABLES -A INPUT -i $LAN -p udp --dport 137 -j ACCEPT # NetBIOS name service udp
$IPTABLES -A INPUT -i $LAN -p udp --dport 138 -j ACCEPT # NetBIOS datagram service
$IPTABLES -A INPUT -i $LAN -p tcp --dport 139 -j ACCEPT # NetBIOS session service File/printer sharing and other operations
$IPTABLES -A INPUT -i $LAN -p tcp --dport 445 -j ACCEPT # Used by Win2k/xp when NetBIOS over TCP/IP is disabled - Microsoft Common Internet File System
$IPTABLES -A INPUT -i $LAN -p udp --dport 445 -j ACCEPT
#$IPTABLES -A INPUT -i $LAN -p tcp --dport 901 -j ACCEPT # used by SWAT (GUI configuration tool for samba)
### Samba END ###
### SSH ###
echo "SSH rules..."
$IPTABLES -A INPUT -i $LAN -p tcp --dport 22 -j ACCEPT # allow ssh connections from lan
### SSH END ###
### Webserver ###
echo "Webserver rules..."
$IPTABLES -A INPUT -i $LAN -p tcp --dport 80 -j ACCEPT # Open Webserver to lan
### Webserver END ###
### DNAT eMULE ###
echo "DNAT eMule..."
$IPTABLES -A FORWARD -j ACCEPT -p tcp --dport 4545
$IPTABLES -t nat -A PREROUTING -i $INET -p tcp --dport 4545 -j DNAT --to 192.168.0.1:4545
$IPTABLES -A FORWARD -j ACCEPT -p udp --dport 4646
$IPTABLES -t nat -A PREROUTING -i $INET -p udp --dport 4646 -j DNAT --to 192.168.0.1:4646
$IPTABLES -A FORWARD -j ACCEPT -p tcp --dport 4661
$IPTABLES -t nat -A PREROUTING -i $INET -p tcp --dport 4661 -j DNAT --to 192.168.0.1:4661
$IPTABLES -A FORWARD -j ACCEPT -p udp --dport 4672
$IPTABLES -t nat -A PREROUTING -i $INET -p udp --dport 4672 -j DNAT --to 192.168.0.1:4672
$IPTABLES -A FORWARD -j ACCEPT -p tcp --dport 4662
$IPTABLES -t nat -A PREROUTING -i $INET -p tcp --dport 4662 -j DNAT --to 192.168.0.1:4662
$IPTABLES -A FORWARD -j ACCEPT -p tcp --dport 4771
$IPTABLES -t nat -A PREROUTING -i $INET -p tcp --dport 4771 -j DNAT --to 192.168.0.1:4771
$IPTABLES -A FORWARD -j ACCEPT -p tcp --dport 3306
$IPTABLES -t nat -A PREROUTING -i $INET -p tcp --dport 3306 -j DNAT --to 192.168.0.1:3306
### DNAT eMULE END ###
# block all outgoing traffic to the internet from port 0:1024
$IPTABLES -A OUTPUT -o $INET -p tcp --sport 1:1024 -j DROP
$IPTABLES -A OUTPUT -o $INET -p udp --sport 1:1024 -j DROP
$IPTABLES -A INPUT -i $INET -j LOG # Log all other input from internet
$IPTABLES -A FORWARD -j LOG --log-prefix "Forward:" # Log all other forward
$IPTABLES -A INPUT -i $LAN -j LOG --log-prefix "from LAN:" # log all other input form lan
# enable forwarding - done last for security
echo " - Enabling forwarding.."
echo "1" > /proc/sys/net/ipv4/ip_forward
# saving iptables rules (works for Redhat/Fedora) (perhaps other distributions too)
/sbin/iptables-save
Script para bloquear facebook en BrazilFW
##BLOQUEO DE FACEBOOK
FACEBOOK_IP_RANGE="31.13.64.0-31.13.127.255 31.13.24.0-31.13.31.255 74.119.76.0-74.119.79.255 69.63.176.0-69.63.191.255 69.171.224.0-69.171.255.255 66.220.144.0-66.220.159.255 204.15.20.0-204.15.23.255 173.252.64.0-173.252.127.255"
iptables -N FACEBOOK
## FACEBOOK DENEGADO
for face in $FACEBOOK_IP_RANGE; do
iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range $face --dport 443 -j FACEBOOK
iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range $face --dport 80 -j FACEBOOK
done
FACEBOOK_ALLOW="192.168.254.101 192.168.254.102 192.168.254.106 192.168.254.107 192.168.254.108 192.168.254.109 192.168.254.110 192.168.254.111 192.168.254.112 192.168.254.113 192.168.254.114 192.168.254.175" #PERMITIDOS
for MSR_LIBERADO in $FACEBOOK_ALLOW; do
iptables -I FACEBOOK -s $MSR_LIBERADO -j ACCEPT
done
iptables -A FACEBOOK -j REJECT
exit 0
FACEBOOK_IP_RANGE="31.13.64.0-31.13.127.255 31.13.24.0-31.13.31.255 74.119.76.0-74.119.79.255 69.63.176.0-69.63.191.255 69.171.224.0-69.171.255.255 66.220.144.0-66.220.159.255 204.15.20.0-204.15.23.255 173.252.64.0-173.252.127.255"
iptables -N FACEBOOK
## FACEBOOK DENEGADO
for face in $FACEBOOK_IP_RANGE; do
iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range $face --dport 443 -j FACEBOOK
iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range $face --dport 80 -j FACEBOOK
done
FACEBOOK_ALLOW="192.168.254.101 192.168.254.102 192.168.254.106 192.168.254.107 192.168.254.108 192.168.254.109 192.168.254.110 192.168.254.111 192.168.254.112 192.168.254.113 192.168.254.114 192.168.254.175" #PERMITIDOS
for MSR_LIBERADO in $FACEBOOK_ALLOW; do
iptables -I FACEBOOK -s $MSR_LIBERADO -j ACCEPT
done
iptables -A FACEBOOK -j REJECT
exit 0
Crear archivo .sh con restricción al youtube en BrazilFW
touch youtube.sh #creo el archivo youtube.sh
edit youtube.sh
luego escribimos las siguientes líneas
#!/bin/sh
echo "Youtube Bloqueado"
iptables -t mangle -A PREROUTING -s 192.168.0.1/24 -p tcp -m string --algo kmp --string "youtube" -j DROP
Presionamos ctrl+Q y luego “Y” para guardar los cambios.
Luego le damos permisos de ejecución:
chmod +x youtube.sh
Finalmente para ejecutarlo simplemente escribimos ./youtube.sh
edit youtube.sh
luego escribimos las siguientes líneas
#!/bin/sh
echo "Youtube Bloqueado"
iptables -t mangle -A PREROUTING -s 192.168.0.1/24 -p tcp -m string --algo kmp --string "youtube" -j DROP
Presionamos ctrl+Q y luego “Y” para guardar los cambios.
Luego le damos permisos de ejecución:
chmod +x youtube.sh
Finalmente para ejecutarlo simplemente escribimos ./youtube.sh
martes, 1 de septiembre de 2015
Bloquear Youtube BrazilFW 3.X
A continuación el scrip para restringir Youtube mediante las iptables en Brazilfw:
iptables -t mangle -A PREROUTING -s 192.168.0.1/24 -p tcp -m string --algo kmp --string "youtube" -j DROP
iptables -t mangle -A PREROUTING -s 192.168.0.1/24 -p tcp -m string --algo kmp --string "youtube" -j DROP
lunes, 3 de octubre de 2011
//Hacer una aplicación que entre una serie de valores numéricos //desde el teclado, los almacene en un vector y sume los elementos //de las posiciones pares, lo mismo que las posiciones impares por separado.
using System;
namespace Sum_Pars_e_Impars
{
class Program
{
public static int[] valores = new int [10];
public static void Main(string[] args)
{
LecturaDatos(valores);
ProcesoDatos(valores);
Console.ReadKey(true);
}
public static void LecturaDatos(int[] par)
{
int i=0;
Console.WriteLine("Ingresa 10 valores numericos ");
while(i<10){
valores[i]=Convert.ToInt16(Console.ReadLine());
i++;
}
}
public static void ProcesoDatos(int[] parm)
{
int par=0, impar=0;
for(int j=0; j<10; j++){
if(j%2==0)
par+=parm[j];
}
for(int m=0; m<10; m++){
if(!(m%2==0))
impar+=parm[m];
}
Console.WriteLine("Suma de las pocisiones pares es: ====> {0}",par);
Console.WriteLine("Suma de las pocisiones impares es: ====> {0}",impar);
}
}
}
namespace Sum_Pars_e_Impars
{
class Program
{
public static int[] valores = new int [10];
public static void Main(string[] args)
{
LecturaDatos(valores);
ProcesoDatos(valores);
Console.ReadKey(true);
}
public static void LecturaDatos(int[] par)
{
int i=0;
Console.WriteLine("Ingresa 10 valores numericos ");
while(i<10){
valores[i]=Convert.ToInt16(Console.ReadLine());
i++;
}
}
public static void ProcesoDatos(int[] parm)
{
int par=0, impar=0;
for(int j=0; j<10; j++){
if(j%2==0)
par+=parm[j];
}
for(int m=0; m<10; m++){
if(!(m%2==0))
impar+=parm[m];
}
Console.WriteLine("Suma de las pocisiones pares es: ====> {0}",par);
Console.WriteLine("Suma de las pocisiones impares es: ====> {0}",impar);
}
}
}
Ordenamiento Burbuja
using System;
namespace Ord_Burbuja
{
class Program
{
public static void Main(string[] args)
{
const int limite=10;
int[ ] lista = new int[limite];
IngresarDatos(lista);
OrderDatos(lista);
VisualizarDatos(lista);
Console.ReadKey(true);
}
public static void IngresarDatos(int[ ] param)
{
for(int i=0;i<param.Length;i++)
{
Console.Write("Ingrese valor [{0}]: ",i);
param[i]=Convert.ToInt16(Console.ReadLine());
}
}
public static void OrderDatos(int[ ] param)
{
int aux;
for(int pasada=0;pasada<param.Length;pasada++)
{
for(int b=0;b<param.Length-1;b++)
{
if(param[b]<param[b+1])
{
aux=param[b];
param[b]=param[b+1];
param[b+1]=aux;
}
}
}
}
public static void VisualizarDatos(int[ ] param)
{
Console.WriteLine("Vector Ordenado...");
for(int i=0;i<param.Length;i++)
{
Console.Write("{0}\n", param[i] + " ");
}
}
}
}
namespace Ord_Burbuja
{
class Program
{
public static void Main(string[] args)
{
const int limite=10;
int[ ] lista = new int[limite];
IngresarDatos(lista);
OrderDatos(lista);
VisualizarDatos(lista);
Console.ReadKey(true);
}
public static void IngresarDatos(int[ ] param)
{
for(int i=0;i<param.Length;i++)
{
Console.Write("Ingrese valor [{0}]: ",i);
param[i]=Convert.ToInt16(Console.ReadLine());
}
}
public static void OrderDatos(int[ ] param)
{
int aux;
for(int pasada=0;pasada<param.Length;pasada++)
{
for(int b=0;b<param.Length-1;b++)
{
if(param[b]<param[b+1])
{
aux=param[b];
param[b]=param[b+1];
param[b+1]=aux;
}
}
}
}
public static void VisualizarDatos(int[ ] param)
{
Console.WriteLine("Vector Ordenado...");
for(int i=0;i<param.Length;i++)
{
Console.Write("{0}\n", param[i] + " ");
}
}
}
}
Números Randomicos
using System;
namespace Num_Randomicos
{
class Program
{
public static void Main(string[] args)
{
Random rnd = new Random( );
const int limite =20;
int[ ] fafi = new int[limite];
for(int i=0;i<limite;i++)
{
fafi[i]=rnd.Next(1,10);
}
for(int i=0;i<limite;i++)
{
Console.WriteLine("Vector [{0}] = {1}",i,fafi[i]);
}
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
namespace Num_Randomicos
{
class Program
{
public static void Main(string[] args)
{
Random rnd = new Random( );
const int limite =20;
int[ ] fafi = new int[limite];
for(int i=0;i<limite;i++)
{
fafi[i]=rnd.Next(1,10);
}
for(int i=0;i<limite;i++)
{
Console.WriteLine("Vector [{0}] = {1}",i,fafi[i]);
}
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
//Hacer una aplicación que forme un vector del que no se sabe el número //de elementos (el tamaño lo indica el usuario). Calcule el promedio //de todos los elementos y forme dos nuevos arreglos, uno con los //elementos menores o iguales al promedio y otro con los superiores. //Imprima los dos nuevos arreglos.
using System;
namespace Prog_Promedios
{
class Program
{
public static int lim;
public static void Main(string[] args)
{
Console.WriteLine("Determine el tamaño del Arreglo ");
lim=Convert.ToInt16(Console.ReadLine());
Console.Clear();
double[] num = new double [lim];
Console.WriteLine("Ingrese los valores ");
for(int t=0; t<lim; t++)
num[t]=Convert.ToDouble(Console.ReadLine());
Procesamiento(num);
Console.ReadKey(true);
}
public static void Procesamiento (double[] pv)
{
double p=0, pf=0;
for(int j=0; j<lim; j++)
p+=pv[j];
pf=p/lim;
Console.WriteLine("Promedio ==> {0}" , pf);
double[] m = new double [lim];
double[] n = new double [lim];
Console.WriteLine("Valores menores al promedio ");
for(int l=0; l<lim; l++){
if(pv[l]<=pf)
m[l]=pv[l];
Console.WriteLine("[{0}]" , m[l]);
}
Console.WriteLine("Valores mayores al promedio ");
for(int e=0; e<lim; e++){
if(pv[e]>=pf)
n[e]=pv[e];
Console.WriteLine("[{0}]" , n[e]);
}
}
}
}
namespace Prog_Promedios
{
class Program
{
public static int lim;
public static void Main(string[] args)
{
Console.WriteLine("Determine el tamaño del Arreglo ");
lim=Convert.ToInt16(Console.ReadLine());
Console.Clear();
double[] num = new double [lim];
Console.WriteLine("Ingrese los valores ");
for(int t=0; t<lim; t++)
num[t]=Convert.ToDouble(Console.ReadLine());
Procesamiento(num);
Console.ReadKey(true);
}
public static void Procesamiento (double[] pv)
{
double p=0, pf=0;
for(int j=0; j<lim; j++)
p+=pv[j];
pf=p/lim;
Console.WriteLine("Promedio ==> {0}" , pf);
double[] m = new double [lim];
double[] n = new double [lim];
Console.WriteLine("Valores menores al promedio ");
for(int l=0; l<lim; l++){
if(pv[l]<=pf)
m[l]=pv[l];
Console.WriteLine("[{0}]" , m[l]);
}
Console.WriteLine("Valores mayores al promedio ");
for(int e=0; e<lim; e++){
if(pv[e]>=pf)
n[e]=pv[e];
Console.WriteLine("[{0}]" , n[e]);
}
}
}
}
//Elaborar una aplicación que forme dos arreglos. El primero contiene los M códigos //de los estudiantes que perdieron LÓGICA DE PROGRAMACION y el segundo los N códigos //de los estudiantes que perdieron ESTRUCTURA DE DATOS. Partiendo de los dos arreglos //formar un nuevo arreglo con los códigos de los estudiantes que perdieron ambas materias.
using System;
namespace Prog_Estudiantes
{
class Program
{
public static void Main(string[] args)
{
string [] logic_prog = {"A5","A14","A21","A23","A25","A29","A33","A39","A41","A42"};
string [] estruc_datos = {"B1","B4","B15","B16","B18","B22","B26","B28","B30","B39"};
Info(logic_prog,estruc_datos);
Console.ReadKey(true);
}
public static void Info(string[] lo_po, string[] es_da)
{
Console.WriteLine("Codigos de alumnos que perdieron ");
Console.WriteLine( "LOGICA DE PROGRAMACION ");
for(int i=0; i<10; i++)
Console.WriteLine(lo_po[i]);
Console.WriteLine("Codigos de alumnos que perdieron ");
Console.WriteLine( "ESTRUCTURA DE DATOS ");
for(int j=0; j<10; j++)
Console.WriteLine(es_da[j]);
NuevoVector(lo_po,es_da);
}
public static void NuevoVector (string[] a, string[] b)
{
string [] uni = new string [10];
Console.WriteLine("Codigos de alumnos que perdieron ");
Console.WriteLine("ESTRUCTURA DE DATOS Y LOGICA DE PROGRAMACION ");
for(int i=0; i<10; i++){
uni[i]=a[i];
Console.WriteLine(uni[i]);
}
for(int m=0; m<10; m++){
uni[m]=b[m];
Console.WriteLine(uni[m]);
}
}
}
}
namespace Prog_Estudiantes
{
class Program
{
public static void Main(string[] args)
{
string [] logic_prog = {"A5","A14","A21","A23","A25","A29","A33","A39","A41","A42"};
string [] estruc_datos = {"B1","B4","B15","B16","B18","B22","B26","B28","B30","B39"};
Info(logic_prog,estruc_datos);
Console.ReadKey(true);
}
public static void Info(string[] lo_po, string[] es_da)
{
Console.WriteLine("Codigos de alumnos que perdieron ");
Console.WriteLine( "LOGICA DE PROGRAMACION ");
for(int i=0; i<10; i++)
Console.WriteLine(lo_po[i]);
Console.WriteLine("Codigos de alumnos que perdieron ");
Console.WriteLine( "ESTRUCTURA DE DATOS ");
for(int j=0; j<10; j++)
Console.WriteLine(es_da[j]);
NuevoVector(lo_po,es_da);
}
public static void NuevoVector (string[] a, string[] b)
{
string [] uni = new string [10];
Console.WriteLine("Codigos de alumnos que perdieron ");
Console.WriteLine("ESTRUCTURA DE DATOS Y LOGICA DE PROGRAMACION ");
for(int i=0; i<10; i++){
uni[i]=a[i];
Console.WriteLine(uni[i]);
}
for(int m=0; m<10; m++){
uni[m]=b[m];
Console.WriteLine(uni[m]);
}
}
}
}
//Elaborar una aplicación que forme un vector B de M elementos //(el tamaño del vector lo define el usuario), luego entre el valor de la variable //CLAVE y la búsqueda secuencialmente dentro del arreglo, suspendiendo la búsqueda //cuando lo encuentre. Imprima un mensaje para el usuario, indicando si encontró //dicho valor o no, en caso afirmativo, indique la posición en la que estaba el dato.
using System;
namespace Prog_busqueda_vector
{
class Program
{
public static void Main(string[] args)
{
int tv;
Console.WriteLine("Define tamaño del vector ");
tv=Convert.ToInt16(Console.ReadLine());
Vector(tv);
Console.ReadKey(true);
}
public static void Vector (int p)
{
Console.Clear();
int i=0;
int[] b = new int [p];
Console.WriteLine("Ingresa los valores al vector ");
do{
b[i]=Convert.ToInt16(Console.ReadLine());
i++;
}while(i<p);
Verificacion(b,p);
}
}
}
namespace Prog_busqueda_vector
{
class Program
{
public static void Main(string[] args)
{
int tv;
Console.WriteLine("Define tamaño del vector ");
tv=Convert.ToInt16(Console.ReadLine());
Vector(tv);
Console.ReadKey(true);
}
public static void Vector (int p)
{
Console.Clear();
int i=0;
int[] b = new int [p];
Console.WriteLine("Ingresa los valores al vector ");
do{
b[i]=Convert.ToInt16(Console.ReadLine());
i++;
}while(i<p);
Verificacion(b,p);
}
}
}
//Ingresar 5 valores numéricos desde el teclado a un arreglo unidimensional, //invertir los valores en un segundo arreglo, visualizar el contenido //de los dos arreglos.
using System;
namespace Prog_arrays_invert
{
class Program
{
public static int[] arreglo = new int [5];
public static void Main(string[] args)
{
Datos(arreglo);
Ejecucion(arreglo);
Console.ReadKey(true);
}
public static void Datos (int[] a)
{
Console.WriteLine("Ingrese 5 valores ");
for(int i=0;i<5;i++)
a[i]=Convert.ToInt16(Console.ReadLine());
}
public static void Ejecucion (int[] b)
{
Console.SetCursorPosition(0,7);
for(int j=0;j<5;j++){
Console.Write("[{0}]" , b[j]);
}
Console.SetCursorPosition(0,9);
for(int p=4;p>=0;p--){
Console.Write("[{0}]" , b[p]);
}
}
}
}
namespace Prog_arrays_invert
{
class Program
{
public static int[] arreglo = new int [5];
public static void Main(string[] args)
{
Datos(arreglo);
Ejecucion(arreglo);
Console.ReadKey(true);
}
public static void Datos (int[] a)
{
Console.WriteLine("Ingrese 5 valores ");
for(int i=0;i<5;i++)
a[i]=Convert.ToInt16(Console.ReadLine());
}
public static void Ejecucion (int[] b)
{
Console.SetCursorPosition(0,7);
for(int j=0;j<5;j++){
Console.Write("[{0}]" , b[j]);
}
Console.SetCursorPosition(0,9);
for(int p=4;p>=0;p--){
Console.Write("[{0}]" , b[p]);
}
}
}
}
//Elaborar un algoritmo que forme dos arreglos relacionados que almacenen los códigos //de los N artículos que se venden en un almacén y la existencia (número de unidades existentes) //de cada uno de los artículos.
using System;
namespace Prog_Almacen
{
class Program
{
public static void Main(string[] args)
{
string op;
int [] cod = {101,102,103,104,105,106,107,108,109,110};
int [] ext = {30,50,20,25,10,40,35,60,80,100};
do{
Datos(cod, ext);
Console.WriteLine("Desea seguir vendiendo/comprando ?"+
" presione S caso contario N ");
op=Convert.ToString(Console.ReadLine());
}while(op=="S"||op=="s");
Mostrar(cod, ext);
Console.ReadKey(true);
}
public static void Datos (int[] codigo, int[] exist)
{
int op, cod1, unidad, cod2;
Console.Clear();
Console.WriteLine("TIPO DE TRANSACCION ");
Console.WriteLine("[1].Provedor (recibo)");
Console.WriteLine("[2].Cliente (venta)");
op=Convert.ToInt16(Console.ReadLine());
if(op==1){
Console.Clear();
Console.WriteLine("Ingrese el codigo del articulo ");
cod1=Convert.ToInt16(Console.ReadLine());
int i=0, aux=0;
while(cod1!=codigo[i]){
i++;
}
aux=i;
Console.WriteLine("Ingrese el numero de unidades a transar ");
unidad=Convert.ToInt16(Console.ReadLine());
exist[aux]=exist[aux]+unidad;
Console.WriteLine("Se agregaron {0}", unidad);
}
if(op==2){
Console.Clear();
Console.WriteLine("Ingrese el codigo del articulo ");
cod2=Convert.ToInt16(Console.ReadLine());
int j=0, aux2=0, unidad2;
while(cod2!=codigo[j]){
j++;
}
aux2=j;
Console.WriteLine("Ingrese el numero de unidades a transar ");
unidad2=Convert.ToInt16(Console.ReadLine());
if(unidad2>exist[aux2])
Console.WriteLine("Error!! No hay stock ");
else{
exist[aux2]=exist[aux2]-unidad2;
Console.WriteLine("Se descontaron {0}", unidad2);
}
}
}
public static void Mostrar (int[] codg, int [] exit)
{
Console.Clear();
Console.WriteLine(" STOCK ACTUAL ");
for(int e=0; e<10; e++)
Console.WriteLine("COD => {0} EXISTENCIA => {1}", codg[e],exit[e]);
}
}
}
namespace Prog_Almacen
{
class Program
{
public static void Main(string[] args)
{
string op;
int [] cod = {101,102,103,104,105,106,107,108,109,110};
int [] ext = {30,50,20,25,10,40,35,60,80,100};
do{
Datos(cod, ext);
Console.WriteLine("Desea seguir vendiendo/comprando ?"+
" presione S caso contario N ");
op=Convert.ToString(Console.ReadLine());
}while(op=="S"||op=="s");
Mostrar(cod, ext);
Console.ReadKey(true);
}
public static void Datos (int[] codigo, int[] exist)
{
int op, cod1, unidad, cod2;
Console.Clear();
Console.WriteLine("TIPO DE TRANSACCION ");
Console.WriteLine("[1].Provedor (recibo)");
Console.WriteLine("[2].Cliente (venta)");
op=Convert.ToInt16(Console.ReadLine());
if(op==1){
Console.Clear();
Console.WriteLine("Ingrese el codigo del articulo ");
cod1=Convert.ToInt16(Console.ReadLine());
int i=0, aux=0;
while(cod1!=codigo[i]){
i++;
}
aux=i;
Console.WriteLine("Ingrese el numero de unidades a transar ");
unidad=Convert.ToInt16(Console.ReadLine());
exist[aux]=exist[aux]+unidad;
Console.WriteLine("Se agregaron {0}", unidad);
}
if(op==2){
Console.Clear();
Console.WriteLine("Ingrese el codigo del articulo ");
cod2=Convert.ToInt16(Console.ReadLine());
int j=0, aux2=0, unidad2;
while(cod2!=codigo[j]){
j++;
}
aux2=j;
Console.WriteLine("Ingrese el numero de unidades a transar ");
unidad2=Convert.ToInt16(Console.ReadLine());
if(unidad2>exist[aux2])
Console.WriteLine("Error!! No hay stock ");
else{
exist[aux2]=exist[aux2]-unidad2;
Console.WriteLine("Se descontaron {0}", unidad2);
}
}
}
public static void Mostrar (int[] codg, int [] exit)
{
Console.Clear();
Console.WriteLine(" STOCK ACTUAL ");
for(int e=0; e<10; e++)
Console.WriteLine("COD => {0} EXISTENCIA => {1}", codg[e],exit[e]);
}
}
}
Productos de arreglos Inversos
//Elaborar una aplicación que lea dos arreglos unidimensionales de igual tamaño
//y forme un tercer arreglo mediante el producto de los elementos de los dos
//arreglos, tomados en orden inverso, es decir, productos del primer elemento
//del primer arreglo, con el último del segundo; del segundo del primer arreglo
//con el penúltimo del segundo arreglo; hasta llegara al último del primer
//arreglo, con el primero del segundo arreglo. Imprimir el arreglo formado.
using System;
namespace Produc_Arreglos_Inversos
{
class Program
{
public static void Main(string[] args)
{
int [] arreg1 = new int [5];
int [] arreg2 = new int [5];
Console.WriteLine("Llenando los arreglos . . ");
Console.WriteLine("Escriba 5 valores del primer arreglo ");
for(int m=0; m<5; m++)
arreg1[m]=Convert.ToInt16(Console.ReadLine());
Console.Clear();
Console.WriteLine("Llenando los arreglos . . ");
Console.WriteLine("Escriba 5 valores del segundo arreglo ");
for(int n=0; n<5; n++)
arreg2[n]=Convert.ToInt16(Console.ReadLine());
MetodoProceso(arreg1,arreg2);
Console.ReadKey(true);
}
public static void MetodoProceso (int[] a1, int[] a2)
{
int e=0;
int[] product = new int [5];
Console.SetCursorPosition(0,8);
Console.WriteLine("Elementos Vector 1");
for(int r=0; r<5; r++){
Console.Write("[{0}]",a1[r]);
}
Console.SetCursorPosition(0,11);
Console.WriteLine("Elementos Vector 2");
for(int t=0; t<5; t++){
Console.Write("[{0}]",a2[t]);
}
Console.SetCursorPosition(0,14);
Console.WriteLine("Producto de Vectores Inversamente ");
while(e<5){
for(int j=4; j>=0; j--){
product[e]=a1[e]*a2[j];
Console.Write("[{0}]",product[e]);
e++;
}
}
}
}
}
//y forme un tercer arreglo mediante el producto de los elementos de los dos
//arreglos, tomados en orden inverso, es decir, productos del primer elemento
//del primer arreglo, con el último del segundo; del segundo del primer arreglo
//con el penúltimo del segundo arreglo; hasta llegara al último del primer
//arreglo, con el primero del segundo arreglo. Imprimir el arreglo formado.
using System;
namespace Produc_Arreglos_Inversos
{
class Program
{
public static void Main(string[] args)
{
int [] arreg1 = new int [5];
int [] arreg2 = new int [5];
Console.WriteLine("Llenando los arreglos . . ");
Console.WriteLine("Escriba 5 valores del primer arreglo ");
for(int m=0; m<5; m++)
arreg1[m]=Convert.ToInt16(Console.ReadLine());
Console.Clear();
Console.WriteLine("Llenando los arreglos . . ");
Console.WriteLine("Escriba 5 valores del segundo arreglo ");
for(int n=0; n<5; n++)
arreg2[n]=Convert.ToInt16(Console.ReadLine());
MetodoProceso(arreg1,arreg2);
Console.ReadKey(true);
}
public static void MetodoProceso (int[] a1, int[] a2)
{
int e=0;
int[] product = new int [5];
Console.SetCursorPosition(0,8);
Console.WriteLine("Elementos Vector 1");
for(int r=0; r<5; r++){
Console.Write("[{0}]",a1[r]);
}
Console.SetCursorPosition(0,11);
Console.WriteLine("Elementos Vector 2");
for(int t=0; t<5; t++){
Console.Write("[{0}]",a2[t]);
}
Console.SetCursorPosition(0,14);
Console.WriteLine("Producto de Vectores Inversamente ");
while(e<5){
for(int j=4; j>=0; j--){
product[e]=a1[e]*a2[j];
Console.Write("[{0}]",product[e]);
e++;
}
}
}
}
}
Números Primos
using System;
using System.Collections.Generic;
namespace _
{
class MainClass
{
public static void Main(string[] args)
{
int cuan=0;
for(int i2=1;i2<=5;i2++)
{
int num;
int acu=0;
Console.WriteLine("Ingrese un valor entero:");
num=Convert.ToInt16 (Console.ReadLine());
acu=verificar6(num);
if(acu<=2)
{
Console.WriteLine("numero primo: {0}",num);
cuan++;
}
else
{
Console.WriteLine("no es numero primo: {0}",num);
}
}
Console.WriteLine ("\n>>>> Existen {0} numeros primos <<<<",cuan);
Console.ReadKey ();
}
public static int verificar6(int b)
{
int a,y=0;
for(int i=1;b>=i;i++)
{
a=b%i;
if(a==0)
{
y=y+1;
}
}
return y;
}
}
}
using System.Collections.Generic;
namespace _
{
class MainClass
{
public static void Main(string[] args)
{
int cuan=0;
for(int i2=1;i2<=5;i2++)
{
int num;
int acu=0;
Console.WriteLine("Ingrese un valor entero:");
num=Convert.ToInt16 (Console.ReadLine());
acu=verificar6(num);
if(acu<=2)
{
Console.WriteLine("numero primo: {0}",num);
cuan++;
}
else
{
Console.WriteLine("no es numero primo: {0}",num);
}
}
Console.WriteLine ("\n>>>> Existen {0} numeros primos <<<<",cuan);
Console.ReadKey ();
}
public static int verificar6(int b)
{
int a,y=0;
for(int i=1;b>=i;i++)
{
a=b%i;
if(a==0)
{
y=y+1;
}
}
return y;
}
}
}
Números par e impar
using System;
using System.Collections.Generic;
namespace vector
{
class MainClass
{
public static void Main(string[] args)
{
const int limite=10;
int[] vector= new int [limite];
leerDatos(vector);
verificarDatosImpares(vector);
Console.ReadKey();
}
public static void leerDatos(int[]param)
{
Console.WriteLine("ingresando datos al vector");
for (int i=0; i<param.Length; i++)
param[i]= Convert.ToInt16(Console.ReadLine());
}
public static void verificarDatosImpares(int[]lista)
{
int p=0, cont=0;
while(p<lista.Length)
{
if(!(lista[p]%2==0))
{
Console.WriteLine("Numero Impar={0},lista[p]");
cont++;
}
p++;
}
Console.WriteLine("Total Numeros Impares={0}",cont);
}
}
}//fin class Main
using System.Collections.Generic;
namespace vector
{
class MainClass
{
public static void Main(string[] args)
{
const int limite=10;
int[] vector= new int [limite];
leerDatos(vector);
verificarDatosImpares(vector);
Console.ReadKey();
}
public static void leerDatos(int[]param)
{
Console.WriteLine("ingresando datos al vector");
for (int i=0; i<param.Length; i++)
param[i]= Convert.ToInt16(Console.ReadLine());
}
public static void verificarDatosImpares(int[]lista)
{
int p=0, cont=0;
while(p<lista.Length)
{
if(!(lista[p]%2==0))
{
Console.WriteLine("Numero Impar={0},lista[p]");
cont++;
}
p++;
}
Console.WriteLine("Total Numeros Impares={0}",cont);
}
}
}//fin class Main
Números aleatorios
using System;
namespace Num_Aleatorios
{
class Program
{
public static void Main(string[] args)
{
Random rnd = new Random( );
int[] num = new int[10];
for(int i=0;i<10;i++)
{
num[i]=rnd.Next(1,30);
}
for(int i=0;i<10;i++)
{
Console.WriteLine("Vector [{0}] = {1}",i,num[i]);
}
Console.ReadKey();
}
}
}
namespace Num_Aleatorios
{
class Program
{
public static void Main(string[] args)
{
Random rnd = new Random( );
int[] num = new int[10];
for(int i=0;i<10;i++)
{
num[i]=rnd.Next(1,30);
}
for(int i=0;i<10;i++)
{
Console.WriteLine("Vector [{0}] = {1}",i,num[i]);
}
Console.ReadKey();
}
}
}
Multiplo de un numero
using System;
using System.Collections.Generic;
namespace Multiplo
{
class MainClass
{
public static void Main(string[] args)
{
int[] vector=new int[10];
leer_var(vector);
proceso(vector);
Console.ReadKey();
}
public static void leer_var(int[]p)
{
Console.WriteLine("ingresando datos al vector");
for(int i=0; i<p.Length;i++)
p[i]=Convert.ToInt16(Console.ReadLine());
}
public static void proceso(int[]p1)
{
int p=0;
while(p<10)
if(p1[p]%3==0)
{
Console.WriteLine("Multiplo de 3{0}",p1[p]);
Console.WriteLine("Posicion{0}",p);
}
p++;
}
}
} //fin class//
using System.Collections.Generic;
namespace Multiplo
{
class MainClass
{
public static void Main(string[] args)
{
int[] vector=new int[10];
leer_var(vector);
proceso(vector);
Console.ReadKey();
}
public static void leer_var(int[]p)
{
Console.WriteLine("ingresando datos al vector");
for(int i=0; i<p.Length;i++)
p[i]=Convert.ToInt16(Console.ReadLine());
}
public static void proceso(int[]p1)
{
int p=0;
while(p<10)
if(p1[p]%3==0)
{
Console.WriteLine("Multiplo de 3{0}",p1[p]);
Console.WriteLine("Posicion{0}",p);
}
p++;
}
}
} //fin class//
Suscribirse a:
Entradas (Atom)




