|
Mostrar Temas
|
Páginas: [1]
|
2
|
Programación / Java / problemas con entender el tema en Java
|
en: 7 Marzo 2016, 02:36 am
|
ayuda porfavor el siguiente programa no me corre quisiera saber que error estoy cometiendo? class Abundantes extends Thread{ public static void main (String args []) { long tini, tfin, ttarda; //Abundantes obj = new Abundantes(); tini =System. currentTimeMillis(); //obj.mostrar_abundantes(10); ttarda=tfin-tini; System. out. println("Tardo: "+ttarda ); } private boolean es_abuntantes(long x){ long i, suma=0; for(i=1;i<=x;i++){ if(x%i==0){ suma+=i; //sumar = suma+i; } } System. out. println(suma +"> 2*"+x ); if(suma>2*x) return true; else return false; } public void run(){ int n; while(n<1){ if(es_abuntantes(n)){ System. out. println(n +"es abundate"); n--; } } } } public static void main (String loquiequiera []){ long inicio_pri, fin_pri, mili_pri; //Gemelos a = new Gemelos(); //a.saludar(); inicio_pri =System. currentTimeMillis(); //a.Mostrar_n_gemelos(10); fin_pri =System. currentTimeMillis(); mili_pri=fin_pri - inicio_pri; System. out. println("MILISEGNDOS=" + mili_pri ); } private boolean primo(long num_a_chk){ int divisibles=0; for(long con_quien=num_a_chk; con_quien>=1; con_quien--){ if(num_a_chk%con_quien == 0 ) divisibles++; } if( divisibles==2 ) return true; else return false; } public void run(){ int n=100; long num_a_chk=3, encontrados=0; while(encontrados<n){ if(primo(num_a_chk)==true && primo(num_a_chk-2) == true ){ System. out. println("Gemelos: "+ (num_a_chk -2) + " , " + num_a_chk ); encontrados++; } num_a_chk++; } } } public class Juntos01 { public static void main (String arg []){ Gemelos a = new Gemelos(); Abundantes b = new Abundantes(); a.start(); b.start(); } }
Mod: Los códigos deben ir en etiquetas GeSHi, los temas d jaa van en s repecivo foro
|
|
|
3
|
Programación / Programación C/C++ / ayuda con punteros a estructura
|
en: 12 Febrero 2016, 04:33 am
|
ayuda necesito saber como hacer para que muestre la direccion de memoria /*11. Dado un arreglo de 10 elementos ={1, 2, 3, 4, 4, 7, 8, 9, 5, 4}, escribir un programa en C (haciendo uso de puntero) que muestre las direcciones de memoria de cada elemento del arreglo.*/ #include <stdio.h> #include <ctype.h> #include <stdlib.h> #define TAM 20 typedef struct Numeros{ //definimos el tipo de dato con typedef int vector; struct Numeros *next; struct Numeros *atras; }DATOS;
DATOS *base, *one, *p; int opc, busca, r, caux, i, j, J; int mas=0; char op;
void agregar(); void mostrar(DATOS *ptr); void pornumero(DATOS *ptr); int main(){ do{ system("reset"); printf("------menu------\n"); printf("A - ingrese los 10 datos\n"); printf("B - mostrar los numeros\n"); printf("S - salir\n"); printf("escoja una opcion\n"); scanf("%c",&opc); opc=toupper(opc); switch(opc){ case 'A' : agregar(p); break; case'B' : system("clear"); if(one!=NULL){ //valida si hay datos o no J=0; p=one; setbuf(stdin,NULL); for(i=0;p!=NULL;i++) { //ciclo que llama a funcion mostrar() mostrar(p); p=p->next; J++; if(J>=4){ J=0; printf("\t\t VER SIGUIENTES...."); getchar(); getchar(); system("clear"); } } printf("\n\t PRESIONE UNA TECLA PARA CONTINUAR..."); } else{ printf("\n\n No existen registros actualmente para mostrar."); } getchar(); getchar(); break; break; } }while(opc!='S'); //fin de ciclo menu principal return 0;
} void agregar(void){ for(i=0;i<10;i++,j++) { //ciclo para agregar datos y llevar registro de datos introducidos. system("clear"); base=(DATOS *) malloc(sizeof(DATOS)); //puntero a bloque printf("datos la posicion %d : ",mas++); scanf("%d",&base->vector); setbuf(stdin,NULL); if(one==NULL){ one=base; base->next=NULL; } else{ base->next=one; one=base; } } }
void mostrar(DATOS *ptr){ printf("\n # valor: %d",ptr->vector); }
|
|
|
4
|
Programación / Programación C/C++ / problema con manejo de nodos en linux
|
en: 10 Febrero 2016, 20:12 pm
|
ayuda tengo un problema con este codigo al compilar en gcc
#include<stdio.h> #include<stdlib.h>
void insertarnodoinicio(); void insertarnodoalfinal(); void insertarentrenodos(); void eliminarnodoinicio(); void eliminarnodofinal(); void eliminarentredosnodos(); void buscarnumero(); void mostrarnodo();
struct dato{ dato *psig; int numero; };
dato *cab=NULL; dato *n=NULL; dato *aux=NULL; dato *p=NULL; dato *q; int x,pos,numerodenodos=0,opc; main() { do{ printf("\n************************* ELIGE UNA OPCION **********************************\n\n"); printf(" 1.-Insertar Un Nodo al Inicio\n"); printf(" 2.-Insertar Un Nodo al Final\n"); printf(" 3.-Insertar entre dos Nodos\n"); printf(" 4.-Mostrar Lista\n"); printf(" 5.-Buscar Nodo\n"); printf(" 6.-Eliminar Nodo al Inicio\n"); printf(" 7.-Eliminar Nodo Final\n"); printf(" 8.-Eliminar Entre dos nodos\n"); printf(" 9.-Salir\n"); printf("\n\nTeclee su opcion: "); scanf("%d",&opc); switch(opc){ case 1: insertarnodoinicio(); break; case 2: insertarnodoalfinal(); break; case 3: insertarentrenodos(); break; case 4: mostrarnodo(); break; case 5: buscarnumero(); break; case 6: eliminarnodoinicio(); break; case 7: eliminarnodofinal(); break; case 8: eliminarentredosnodos(); break; case 9: exit(0);break; default: printf("Opcion no valida");break; } }while(opc!=9); getch(); } void eliminarentredosnodos() { q=cab; int h=1; if (cab=NULL) printf("La lista esta vacia"); else { printf("Ingrese Nodo a eliminar: "); scanf("%d",&x); while (q->numero!=x && h==1) { if (q->psig!=NULL) { p=q; q=q->psig; } else h=0; } if (p->psig==NULL) printf("Elemento no Encontardo"); else { if (cab=q) cab=q->psig; else p->psig=q->psig; } delete(q); } getch(); system("CLS"); } void eliminarnodofinal() { p=cab; if (cab==NULL) printf("No hay Numeros en la lista"); if (cab->psig==NULL) { delete (cab); cab=NULL; } else { while(p->psig!=NULL) { aux=p; p=p->psig; } aux->psig=NULL; delete p; numerodenodos--; } getch(); system("cls"); }
void eliminarnodoinicio() { if (cab==NULL) printf("No hay numeros que eliminar"); else { aux=cab; cab=cab->psig; delete (aux); aux=NULL; numerodenodos--; } getch(); system("cls"); } void buscarnumero() { int eli; if (cab==NULL) { printf("No hay numeros en la lista"); } else { q=cab; printf("Que Numero desea buscar: "); scanf("%d",&x); pos=1; while(q!=NULL && q->numero!=x) { q=q->psig; pos++; } if (q!=NULL) printf("%d Esta en la lista y en la posicion %d\n",x,pos); else { printf("%d No esta en la lista\n",x); } }
getch(); system("cls"); } void insertarnodoinicio(){ n=(dato*)malloc(sizeof (struct dato)); printf("\nElementos a insertar: "); scanf("%d",&x); n->numero=x; n->psig=NULL; if(cab==NULL) cab=n; else{ n->psig=cab; cab=n; } numerodenodos++; system("CLS"); } void mostrarnodo() { if(cab==NULL) printf("Lista vacia.........\n"); else{ p=cab; printf("\nLista de numeros...\n"); while(p!=NULL){ printf("\n%d\n",p->numero); p=p->psig; } printf("\nEl numero de nodos es: %d ",numerodenodos); } getch(); system("CLS"); } void insertarnodoalfinal() { n= (dato*)malloc(sizeof(dato)); printf("Ingresa dato: "); scanf("%d",&x); n->numero=x; n->psig=NULL; if(cab==NULL){ cab=n; numerodenodos++; } else{ p=cab; while(p->psig!=NULL) { p=p->psig; } p->psig=n; numerodenodos++; } getch(); system("CLS"); } void insertarentrenodos() { if(cab==NULL) printf("No hay elementos"); else { printf("Ingrese la posicion en que desees insertar: "); scanf("%d",&pos); if(pos> numerodenodos || pos==1) printf("Solamente es valido entre 2 nodos"); else { n=(dato*)malloc(sizeof(dato)); printf("Ingresa dato: "); scanf("%d",&x); n->numero=x; n->psig=NULL; aux=cab; for(int i=1; i<pos-1; i++) { aux=aux->psig; } n->psig=aux->psig; aux->psig=n; numerodenodos++; } } getch(); system("cls"); }
tengo este programa pero tengo un error cuando intento compilar con gcc me marca lo siguiente alguien ayuda ListasSimples.c:16:3: error: unknown type name ‘dato’ dato *psig; ^ ListasSimples.c:20:7: error: unknown type name ‘dato’ dato *cab=NULL; ^ ListasSimples.c:21:7: error: unknown type name ‘dato’ dato *n=NULL; ^ ListasSimples.c:22:7: error: unknown type name ‘dato’ dato *aux=NULL; ^ ListasSimples.c:23:7: error: unknown type name ‘dato’ dato *p=NULL; ^ ListasSimples.c:24:7: error: unknown type name ‘dato’ dato *q; ^ ListasSimples.c:27:7: warning: return type defaults to ‘int’ [-Wimplicit-int] main() ^ ListasSimples.c: In function ‘main’: ListasSimples.c:84:37: warning: implicit declaration of function ‘getch’ [-Wimplicit-function-declaration] getch(); ^ ListasSimples.c: In function ‘eliminarentredosnodos’: ListasSimples.c:104:22: error: request for member ‘numero’ in something not a structure or union while (q->numero!=x && h==1) ^ ListasSimples.c:106:19: error: request for member ‘psig’ in something not a structure or union if (q->psig!=NULL) ^ ListasSimples.c:109:35: error: request for member ‘psig’ in something not a structure or union q=q->psig; ^ ListasSimples.c:115:24: error: request for member ‘psig’ in something not a structure or union if (p->psig==NULL) ^ ListasSimples.c:120:28: error: request for member ‘psig’ in something not a structure or union cab=q->psig; ^ ListasSimples.c:122:24: error: request for member ‘psig’ in something not a structure or union p->psig=q->psig; ^ ListasSimples.c:122:32: error: request for member ‘psig’ in something not a structure or union p->psig=q->psig; ^ ListasSimples.c:125:19: warning: implicit declaration of function ‘delete’ [-Wimplicit-function-declaration] delete(q); ^ ListasSimples.c: In function ‘eliminarnodofinal’: ListasSimples.c:140:12: error: request for member ‘psig’ in something not a structure or union if (cab->psig==NULL) ^ ListasSimples.c:149:12: error: request for member ‘psig’ in something not a structure or union while(p->psig!=NULL) ^ ListasSimples.c:152:8: error: request for member ‘psig’ in something not a structure or union p=p->psig; ^ ListasSimples.c:154:8: error: request for member ‘psig’ in something not a structure or union aux->psig=NULL; ^ ListasSimples.c:155:5: error: unknown type name ‘delete’ delete p; ^ ListasSimples.c: In function ‘eliminarnodoinicio’: ListasSimples.c:176:17: error: request for member ‘psig’ in something not a structure or union cab=cab->psig; ^ ListasSimples.c: In function ‘buscarnumero’: ListasSimples.c:200:24: error: request for member ‘numero’ in something not a structure or union while(q!=NULL && q->numero!=x) ^ ListasSimples.c:202:9: error: request for member ‘psig’ in something not a structure or union q=q->psig; ^ ListasSimples.c: In function ‘insertarnodoinicio’: ListasSimples.c:223:5: error: ‘dato’ undeclared (first use in this function) n=(dato*)malloc(sizeof (struct dato)); ^ ListasSimples.c:223:5: note: each undeclared identifier is reported only once for each function it appears in ListasSimples.c:223:10: error: expected expression before ‘)’ token n=(dato*)malloc(sizeof (struct dato)); ^ ListasSimples.c:226:3: error: request for member ‘numero’ in something not a structure or union n->numero=x; ^ ListasSimples.c:227:3: error: request for member ‘psig’ in something not a structure or union n->psig=NULL; ^ ListasSimples.c:232:3: error: request for member ‘psig’ in something not a structure or union n->psig=cab; ^ ListasSimples.c: In function ‘mostrarnodo’: ListasSimples.c:250:19: error: request for member ‘numero’ in something not a structure or union printf("\n%d\n",p->numero); ^ ListasSimples.c:251:5: error: request for member ‘psig’ in something not a structure or union p=p->psig; ^ ListasSimples.c: In function ‘insertarnodoalfinal’: ListasSimples.c:263:6: error: ‘dato’ undeclared (first use in this function) n= (dato*)malloc(sizeof(dato)); ^ ListasSimples.c:263:11: error: expected expression before ‘)’ token n= (dato*)malloc(sizeof(dato)); ^ ListasSimples.c:266:3: error: request for member ‘numero’ in something not a structure or union n->numero=x; ^ ListasSimples.c:267:3: error: request for member ‘psig’ in something not a structure or union n->psig=NULL; ^ ListasSimples.c:274:9: error: request for member ‘psig’ in something not a structure or union while(p->psig!=NULL) ^ ListasSimples.c:276:5: error: request for member ‘psig’ in something not a structure or union p=p->psig; ^ ListasSimples.c:278:3: error: request for member ‘psig’ in something not a structure or union p->psig=n; ^ ListasSimples.c: In function ‘insertarentrenodos’: ListasSimples.c:301:21: error: ‘dato’ undeclared (first use in this function) n=(dato*)malloc(sizeof(dato)); ^ ListasSimples.c:301:26: error: expected expression before ‘)’ token n=(dato*)malloc(sizeof(dato)); ^ ListasSimples.c:304:19: error: request for member ‘numero’ in something not a structure or union n->numero=x; ^ ListasSimples.c:305:19: error: request for member ‘psig’ in something not a structure or union n->psig=NULL; ^ ListasSimples.c:310:25: error: request for member ‘psig’ in something not a structure or union aux=aux->psig; ^ ListasSimples.c:312:19: error: request for member ‘psig’ in something not a structure or union n->psig=aux->psig; ^ ListasSimples.c:312:29: error: request for member ‘psig’ in something not a structure or union n->psig=aux->psig; ^ ListasSimples.c:313:21: error: request for member ‘psig’ in something not a structure or union aux->psig=n;
|
|
|
|
|
|
|