elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Los 10 CVE más críticos (peligrosos) de 2020


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Menú con funciones, no se si lo esta haciendo bien.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Menú con funciones, no se si lo esta haciendo bien.  (Leído 2,319 veces)
ivanel93

Desconectado Desconectado

Mensajes: 10


Ver Perfil
Menú con funciones, no se si lo esta haciendo bien.
« en: 10 Marzo 2013, 09:00 am »

Hola muchachos es la segunda vez que pido ayuda emm tengo un problema? , bueno no he entendido del todo el tema de los nodos y estructuras en c (mi profe no domina el tema, y quiere que le entendamos a la primera), puesto que me han dejado un código incompleto el cual he tratado de terminar bueno principalmente me enfoco a que tengo que desarrollar una rutina de generar la función seno y senh-1  pero al ejecutar mi programa no se si estén correctos los valores que este muestra solicito su colaboración para ver si lo que he estado haciendo esta bien, no entiendo el tema espero me ayuden muchas gracias de antemano .
Anexo el código para que lo chequen :







Código
  1. /* PROGRAMA: SUMA, RESTA, MULTIPLICACION Y DIVISION DE POLINOMIOS */
  2. # include <stdio.h>
  3. # include <stdlib.h>
  4. # include <alloc.h>
  5. # include <conio.h>
  6. # include <dos.h>
  7. # include <string.h>
  8.  
  9. # include <math.h>
  10.  
  11. # define DELAY 64000
  12.  
  13. struct apuntador
  14. {
  15. float coef;
  16. int exp1;
  17. struct apuntador *siguiente;
  18. } nodo;
  19.  
  20. struct apuntador
  21. *polydat1, *polydat2, *polysum1, *polysum2, *polysuma, *polymin,
  22. *polysus, *polyres, *polyfac1, *polyfac2, *polyprod, *polynum,
  23. *polyden, *polycos, *polyresta, *polyresul, *aux_poly, *nuevo,
  24. *polyder;
  25.  
  26. void pausa(void), crea(void), iniciapoly(void),
  27. presentacion(void),
  28. insert_lista(struct apuntador **poly, float c, int e),
  29. imprime(struct apuntador *poly),
  30. suma_poly(struct apuntador *poly1, struct apuntador *poly2,
  31. struct apuntador **poly3),
  32. multy_poly(struct apuntador *poly1, struct apuntador *poly2,
  33. struct apuntador **poly3),
  34. resta_poly(struct apuntador *poly1, struct apuntador *poly2,
  35. struct apuntador **poly3),
  36. div_poly(struct apuntador *poly1, struct apuntador *poly2,
  37. struct apuntador **poly3, struct apuntador **poly4),
  38. der_poly(struct apuntador *poly1, struct apuntador **poly3),
  39. borrar_poly(struct apuntador **poly3, int e);
  40. float eval_poly(struct apuntador *poly1,float x);
  41. float factorial(int);
  42.  
  43.  
  44. int seleccion_menu(void);
  45. int i,caso,e;
  46. float c,epsilon;
  47. float coef;
  48. int exp1,fx,x0;  // SE CAMBIA EXP SOLO AQUI O EN TODOS?
  49. char n;
  50. int opcion;
  51.  
  52. main()
  53. {
  54.  presentacion();
  55.  clrscr();
  56.  for(;;)
  57. {
  58. switch(seleccion_menu())
  59. {
  60.  
  61.  
  62.  case 1:
  63.  int limite, iter=0;
  64.  float fxd,epsilon,xa,xn;
  65.  clrscr();
  66.  printf("\n Metodo de Newton Raphson (RAICES) de poly1");
  67.  printf("\n Dame el valor inicial de x0    para poly1 ==>");
  68.  scanf("%f",&x0);
  69.  printf("\n Dame el Epsilon ==>");
  70.  scanf("%f",&epsilon);
  71.  printf("\n Dame el nuemro maximo de iteraciones ==>");
  72.  scanf("%d",&limite);
  73.  der_poly(polydat1, &polyder);
  74.  printf("\n #iter----x0----------fx----------fxd----------xn");
  75.  do
  76. {
  77. xa=x0;
  78. fx=eval_poly(polydat1,xa);
  79. fxd=eval_poly(polyder,xa);
  80. xn=xa - fx/fxd;
  81. iter=iter+1;
  82. printf("\n %d   %f   %f   %f   %f",iter,xa,fx,fxd,xn);
  83. x0=xn;
  84. } while((fabs(xa-xn)>epsilon)&&(iter<=limite));
  85.  printf("\n el valor final de x es = 5f",xn);
  86.  printf("\n\n");
  87.  pausa();
  88.  pausa();
  89.  pausa();
  90.  break;
  91.  
  92.  
  93.  case 2:
  94. clrscr();  
  95.        iniciapoly();
  96. do
  97.  {     do
  98.  {
  99. printf("\n Dame el valor del coeficiente del poly 1 ==> ");
  100. scanf("%f",&c);
  101. } while (c == 0);
  102.  
  103. printf("\n Dame el valor del exponente del poly 1   ==> ");
  104. scanf("%d",&e);
  105. insert_lista(&polydat1,c,e);
  106. printf("\n Desea otro termino (s/n) ? ==> ");
  107. opcion=getche();
  108.  }  while((opcion==115) || (opcion==83));
  109.  imprime(polydat1);
  110.  printf("\n\n");
  111.  do
  112. {
  113. do
  114.  {
  115. printf("\n Dame el valor del coeficiente del poly 2 ==> ");
  116. scanf("%f",&c);
  117. } while (c == 0);
  118. printf("\n Dame el valor del exponente de poly 2    ==> ");
  119. scanf("%d",&e);
  120. insert_lista(&polydat2,c,e);
  121. printf("\n Desea otro termino (s/n) ? ==> ");
  122. opcion=getche();
  123. }  while((opcion==115) || (opcion==83));
  124. imprime(polydat2);
  125. pausa();
  126. break;
  127.  case 3:
  128. polysum1=polydat1;
  129. polysum2=polydat2;
  130. suma_poly(polysum1,polysum2,&polysuma);
  131. imprime(polysuma);
  132. pausa();
  133. break;
  134.  case 4:
  135. polyfac1=polydat1;
  136. polyfac2=polydat2;
  137. multy_poly(polyfac1,polyfac2,&polyprod);
  138. imprime(polyprod);
  139. pausa();
  140. break;
  141.  case 5:
  142. polymin=polydat1;
  143. polysus=polydat2;
  144. resta_poly(polymin,polysus,&polyresta);
  145. imprime(polyresta);
  146. pausa();
  147. break;
  148.  case 6:
  149. polyder = polydat1;
  150. der_poly(polydat1,&polyder);
  151. printf("Derivada:\n");
  152. imprime(polyder);
  153. pausa();
  154. break;
  155.  case 7:
  156. printf("\ Fin del Programa");
  157. exit(0);
  158. default:
  159. printf("\n Operacion no valida");
  160. //return (0);
  161.  
  162.  case 8:
  163. fx=eval_poly(polydat1,x0);
  164. break;
  165.  case 9:
  166.  
  167. break;
  168.  case 10:
  169. clrscr();
  170. printf("\n Dame el valor del exponente del termino a borrar de poly1 ==> ");
  171. scanf("%d",&e);
  172. borrar_poly(&polydat1,e);
  173. imprime(polydat1);
  174. printf("\n\n");
  175. pausa();
  176. break;
  177.  
  178.  
  179.  
  180.  case 11:
  181. struct apuntador *fx;
  182. fx=polydat1;
  183. float a,b,c,it_limit,fa,fb,fc;
  184. int it=0;
  185. while(1)
  186. {//0
  187. clrscr();
  188. printf("\n Metodo de la biseccion (PARA RAICES) de poly1");
  189. printf("\n dar la cota inferior a = ?");
  190. scanf("%f",&a);
  191. printf("\n dar la cota superior b = ?");
  192. scanf("%f",&b);
  193. printf("\n Dar el epsilon ==> ?");
  194. scanf("%f",&epsilon);
  195. printf("\n Dar el limite de iteraciones =? ");
  196. scanf("%f",&it_limit);
  197. printf("\n It.--a-----b-----c-----f(a)-----f(c)-----abs(f(c)-f(a))/2");
  198. fa= eval_poly(fx,a);
  199. fb= eval_poly(fx,b);
  200. if((fa*fb)>0)
  201.  {//1
  202. printf("\n La solucion no esta entre a..b ya que f(a) f(b)>0 \n");
  203.  } //-1
  204. else
  205.  while(1)
  206. {//2
  207. it=it+1;
  208. c=(a+b)/2;
  209. fc=eval_poly(fx,c);
  210. printf("\n %3d  %10.6f  %10.6f  %10.6f  %10.6f  %10.6f",it,a,c,b,fa,fc);
  211. printf("\n %14.8f \n",fabs((fb-fa)/2));
  212. pausa();
  213. if(it>it_limit)
  214. break;
  215. if(fabs(c-a)<epsilon)
  216. break;
  217. if(fa*fc<=0)
  218.  { b=c; fb=fc; }
  219. else
  220.  { a=c; fa=fc; }
  221. }//-2
  222. if(it<=it_limit)
  223.  printf("\n Tolerancia satisfecha");
  224. if(it>it_limit)
  225.  printf("\n limite exedido de iteraciones");
  226.  printf("\n el resultado final de x es =%g \n",c);
  227.  printf("\n\n");
  228.  
  229.  pausa();
  230.  pausa();
  231.  }//0
  232. break;
  233.  
  234. case 12:
  235. struct apuntador *fsen=NULL;
  236. int t,expo,signo;
  237. double coefi,x,ter;
  238. double suma=0;
  239. double vfsen;
  240. clrscr();
  241. printf("\n Dar el valor de terminos: ");
  242. scanf("%d",&t);
  243. printf("\n Dar el valor de X: ");
  244. scanf("%f",&x);
  245. x=x*3.1416/180;
  246. printf("\n #ter sig  exp    coefi        ter         suma");
  247. for(int ni=0;ni<t;ni++)
  248.  {
  249. signo=pow(-1,ni);
  250. expo=2*ni+1;
  251. coefi=signo/factorial(expo);
  252. insert_lista(&fsen,coefi,expo);
  253. ter=coefi*pow(x,expo);
  254. suma=suma+ter;
  255. printf("\n\n %2d   %2d   %2d  %10.8f  %10.8f  %10.8f",ni+1,signo,expo,coefi,ter,suma);
  256.  }
  257. printf("\n\n\n El valor sel seno con sumatoria es : %14.12f\n\n",suma);
  258. getche();
  259. imprime(fsen);
  260. vfsen=eval_poly(fsen,x);
  261. printf("\n\n El valor del seno con polinomio es : %14.12f",vfsen);
  262. getche();
  263. polydat1=fsen;
  264. printf("\n\n");
  265. pausa();
  266. break;
  267.  
  268. case 13:
  269. struct apuntador *fsinhmu=NULL;
  270.  
  271.         int te,expon,sign;
  272. double coefic,xi,termin,dn;
  273. double sumas=0;
  274. double vfsinhmu;
  275.  
  276.         clrscr();
  277. printf("\n Dar el valor de terminos: ");
  278. scanf("%d",&te);
  279. printf("\n Dar el valor de X: ");
  280. scanf("%f",&xi);
  281. xi=xi*3.1416/180;
  282. printf("\n #Term Signo  Exp   Coeficiente   Termino      Suma");
  283. for(int n=0;n<te;n++)
  284.  {
  285. sign=pow(-1,n);
  286. expon=2*n+1;
  287. dn=2*n;
  288. coefic=(sign*factorial(dn))/(pow(4,n)*pow(factorial(n),2)*expon);
  289. insert_lista(&fsinhmu,coefic,expon);
  290. termin=coefic*pow(xi,expon);
  291. sumas=sumas+termin;
  292. printf("\n\n   %2d    %2d   %2d    %10.8f   %10.8f   %10.8f",n+1,sign,expon,coefic,termin,sumas);
  293.  }
  294. printf("\n\n\n El valor sel seno con sumatoria es : %14.12f\n\n",sumas);
  295. getche();
  296. imprime(fsinhmu);
  297. vfsinhmu=eval_poly(fsinhmu,xi);
  298. printf("\n\n El valor del seno con polinomio es : %14.12f",vfsinhmu);
  299. getche();
  300. polydat1=fsinhmu;
  301. printf("\n\n");
  302. pausa();
  303. break;
  304.  
  305. }
  306. }
  307. }
  308.  
  309. seleccion_menu(void)
  310. {
  311. char s[80];
  312. int x;
  313. clrscr();
  314. printf("\n\n          OPERACIONES DE POLINOMIOS:");
  315. printf("\n\n\n             1 ) Metodo de Newton Rhapson \n");
  316. printf("                   2 ) Crear polinomio. \n");
  317. printf("                   3 ) Suma. \n");
  318. printf("                   4 ) Multiplicacion. \n");
  319. printf("                   5 ) Resta. \n");
  320. printf("                   6 ) Derivada. \n");
  321. printf("                   7 ) Salir. \n");
  322. printf("                   8 ) Evaluar polyn(x). \n");
  323. printf("                   9 ) Modificar termino de polinomio.\n");
  324. printf("                   10 ) Borrar algun termino. \n");
  325. printf("                   11 )  Metodo de Biseccion \n");
  326. printf("                   12 )  Genera funcion Seno de Taylor \n");
  327. printf("                   13 )  Genera funcion SenoHyperbolico Inverso \n");
  328. do
  329. {
  330. printf("                                   OPCION ==> ");
  331. gets(s);
  332. x=atoi(s);
  333. }  while (x<0 || x>14);
  334. return (x);
  335. }
  336.  
  337. void pausa(void)
  338. {
  339. printf("\n Pulsar cualquier tecla para continuar...");
  340. getch();
  341. }
  342.  
  343. void iniciapoly(void)
  344. {
  345. polydat1=NULL;
  346. polydat2=NULL;
  347. polysum1=NULL;
  348. polysum2=NULL;
  349. polysuma=NULL;
  350. polymin=NULL;
  351. polysus=NULL;
  352. polyres=NULL;
  353. polyfac1=NULL;
  354. polyfac2=NULL;
  355. polyprod=NULL;
  356. polynum=NULL;
  357. polyden=NULL;
  358. polycos=NULL;
  359. polyres=NULL;
  360. polyresta=NULL;
  361. polyder=NULL;
  362. }
  363.  
  364. void insert_lista(struct apuntador **poly, float coefi, int expo)
  365. { //0
  366. struct apuntador *nuevo, *aux,*ant;
  367. int band=0;
  368. nuevo=(struct apuntador *) malloc (sizeof(nodo));
  369. if(nuevo == NULL)
  370. {//1
  371. printf("MEMORIA AGOTADA \n");
  372. return;
  373. }//-1
  374. nuevo->coef=coefi;
  375. nuevo->exp1=expo;
  376. nuevo->siguiente=NULL;
  377. if(*poly==NULL)
  378. *poly=nuevo;
  379. else
  380. {//-2
  381. aux=*poly;
  382. if(aux->exp1 < expo)
  383. { //3
  384. nuevo->siguiente=*poly;
  385. *poly=nuevo;
  386. }//-3
  387. else //EN OTRSOS CASOS
  388. {//4
  389. while((aux)&&(band))
  390.  {//5
  391. if(aux->exp1==expo)
  392.  {//6 PARA TERMINO CON IGUAL EXPONENTE
  393. aux->coef=aux->coef+coefi;
  394. delete(nuevo); // O ES "if(aux->coef==0)"
  395. band=1;
  396.  }//-6
  397. else //PARA EL CASO: aux->exp1>expo
  398.  {//7
  399. if((aux->siguiente!= NULL)&&(expo>aux->siguiente->exp1))
  400. {//8
  401.  nuevo->siguiente=aux->siguiente;
  402.  aux->siguiente=nuevo;
  403.  band=1;
  404. }//-8
  405. else
  406. {//9
  407.  if(aux->siguiente==NULL)
  408. {//10
  409. aux->siguiente=nuevo;
  410. band=1;
  411. }//-10
  412.  else
  413. ant=aux;
  414. aux=aux->siguiente;
  415. }//-9
  416.  }//-7
  417.  }//-5
  418. }//-4
  419. }
  420. }//-0
  421.  
  422. void imprime(struct apuntador *poly)
  423. {
  424. while(poly)
  425. {
  426. printf("\n\n Coeficiente : %f \n",poly->coef);
  427. printf(" Exponente   : %i",poly->exp1);
  428. poly=poly->siguiente;
  429. }
  430. }
  431.  
  432. void suma_poly(struct apuntador *poly1, struct apuntador *poly2,
  433. struct apuntador **poly3)
  434. {
  435. float suma;
  436. struct apuntador *primero;
  437. primero = NULL;
  438. suma=0;
  439. while((poly1 != NULL) && (poly2 != NULL))
  440. {
  441. if (poly1->exp1 == poly2-> exp1)
  442. {
  443. suma=poly1->coef + poly2->coef;
  444. if(suma !=0)
  445. {
  446. insert_lista(&primero,suma,poly1->exp1);
  447. }
  448. poly1=poly1->siguiente;
  449. poly2=poly2->siguiente;
  450. }
  451. else
  452. if(poly1->exp1 > poly2->exp1)
  453. {
  454. insert_lista(&primero,poly1->coef,poly1->exp1);
  455. poly1=poly1->siguiente;
  456. }
  457. else
  458. {
  459. insert_lista(&primero,poly2->coef,poly2->exp1);
  460. poly2=poly2->siguiente;
  461. }
  462. suma=0;
  463. }
  464. while(poly1 != NULL)
  465. {
  466. insert_lista(&primero,poly1->coef,poly1->exp1);
  467. poly1=poly1->siguiente;
  468. }
  469. while(poly2 != NULL)
  470. {
  471. insert_lista(&primero,poly2->coef,poly2->exp1);
  472. poly2=poly2->siguiente;
  473. }
  474. *poly3 = primero;
  475. }
  476.  
  477. void multy_poly(struct apuntador *poly1, struct apuntador *poly2,
  478. struct apuntador **poly3)
  479. {
  480. struct apuntador *primero;
  481. float multy;
  482. int sum;
  483. struct apuntador *p, *q, *aux1, *aux2;
  484.  
  485. primero = NULL;
  486. *poly3=NULL;
  487. multy=1;
  488. sum=0;
  489. while(poly2 != NULL)
  490. {
  491. p=poly1;
  492. while(p!=NULL)
  493. {
  494. multy=p->coef *poly2->coef;
  495. sum=p->exp1 + poly2->exp1;
  496. if(multy != 0)
  497. {
  498. insert_lista(&primero,multy,sum);
  499. p=p->siguiente;
  500. }
  501. else
  502. {
  503. insert_lista(&primero,p->coef,p->exp1);
  504. p=p->siguiente;
  505. poly2=poly2->siguiente;
  506. }
  507. multy=1;
  508. }
  509. poly2=poly2->siguiente;
  510. }
  511. q = primero;
  512. while(q)
  513. {
  514. if(q->exp1==q->siguiente->exp1)
  515. {
  516. q->coef=q->coef + q->siguiente->coef;
  517. q->siguiente=q->siguiente->siguiente;
  518. }
  519. else
  520. q=q->siguiente;
  521. }
  522. *poly3=primero;
  523. }
  524.  
  525. void resta_poly(struct apuntador *poly1, struct apuntador *poly2,
  526. struct apuntador **poly3)
  527. {
  528.    float resta;
  529.    struct apuntador *primero;
  530. primero = NULL;
  531. resta= 0;
  532.    while ((poly1 != NULL) && (poly2 != NULL))
  533. {
  534.  if (poly1->exp1 == poly2->exp1)
  535. {
  536. resta= poly1->coef - poly2->coef;
  537. if (resta != 0) {
  538. insert_lista (&primero, resta, poly1->exp1); }
  539. poly1= poly1->siguiente;
  540. poly2= poly2->siguiente;
  541. }
  542.  else
  543. if (poly1->exp1 > poly2->exp1)
  544. {
  545. insert_lista (&primero, poly1->coef, poly1->exp1);
  546. poly1= poly1->siguiente;
  547. }
  548. else
  549. {
  550. insert_lista (&primero, poly2->coef, poly2->exp1);
  551. poly2= poly2->siguiente;
  552. }
  553. resta= 0;
  554. }
  555.  
  556. while (poly1 != NULL)
  557. {
  558. insert_lista (&primero, poly1->coef, poly1->exp1);
  559. poly1= poly1->siguiente;
  560. }
  561.  
  562.    while (poly2 != NULL)
  563. {
  564. insert_lista (&primero, -poly2->coef, poly2->exp1);
  565.   poly2= poly2->siguiente;
  566. }
  567.      *poly3 = primero;
  568. }
  569.  
  570. void borrar_poly(struct apuntador **poly, int expo)
  571. {
  572. // aqui va el codigo correspondiente
  573. }
  574.  
  575. void div_poly(struct apuntador *polynume, struct apuntador *polydeno,
  576. struct apuntador **polycoci, struct apuntador **polyresi)
  577. {
  578.  
  579. }
  580.  
  581. void der_poly(struct apuntador *poly1,struct apuntador **poly3)
  582. {
  583. struct apuntador *primero=NULL;
  584. float co=0;
  585. int ex=0;
  586.  while((poly1!=NULL)&&(poly1->exp1!=0))
  587. {
  588. co=poly1->coef*poly1->exp1;
  589. ex=poly1->exp1-1;
  590. insert_lista(&primero,co,ex);
  591. poly1=poly1->siguiente;
  592. }
  593. }
  594.  
  595. float eval_poly(struct apuntador *poly1, float ev)
  596. {
  597.  float res2;
  598.  res2=0;
  599.  while(poly1)
  600. {
  601. res2=res2+poly1->coef*pow(ev,poly1->exp1);
  602. poly1=poly1->siguiente;
  603. }
  604. return (res2);
  605. }
  606.  
  607. void presentacion(void)
  608. {
  609. char c[1];
  610. clrscr();
  611. printf("\n\n                      PROGRAMA POLINOMIO \n\n");
  612. printf("          REALIZA LA SUMA, RESTA, MULTIPLICACION Y DIVISION \n\n");
  613.  
  614. }
  615.  
  616. float factorial(int n)
  617.  {
  618.   int k;
  619.   float f=1;
  620.   for(k=1;k<=n;k++)
  621.      f=f*k;
  622.   return(f);
  623.  }
  624. /* PROGRAMA: SUMA, RESTA, MULTIPLICACION Y DIVISION DE POLINOMIOS */
  625. # include <stdio.h>
  626. # include <stdlib.h>
  627. # include <alloc.h>
  628. # include <conio.h>
  629. # include <dos.h>
  630. # include <string.h>
  631.  
  632. # include <math.h>
  633.  
  634. # define DELAY 64000
  635.  
  636. struct apuntador
  637. {
  638. float coef;
  639. int exp1;
  640. struct apuntador *siguiente;
  641. } nodo;
  642.  
  643. struct apuntador
  644. *polydat1, *polydat2, *polysum1, *polysum2, *polysuma, *polymin,
  645. *polysus, *polyres, *polyfac1, *polyfac2, *polyprod, *polynum,
  646. *polyden, *polycos, *polyresta, *polyresul, *aux_poly, *nuevo,
  647. *polyder;
  648.  
  649. void pausa(void), crea(void), iniciapoly(void),
  650. presentacion(void),
  651. insert_lista(struct apuntador **poly, float c, int e),
  652. imprime(struct apuntador *poly),
  653. suma_poly(struct apuntador *poly1, struct apuntador *poly2,
  654. struct apuntador **poly3),
  655. multy_poly(struct apuntador *poly1, struct apuntador *poly2,
  656. struct apuntador **poly3),
  657. resta_poly(struct apuntador *poly1, struct apuntador *poly2,
  658. struct apuntador **poly3),
  659. div_poly(struct apuntador *poly1, struct apuntador *poly2,
  660. struct apuntador **poly3, struct apuntador **poly4),
  661. der_poly(struct apuntador *poly1, struct apuntador **poly3),
  662. borrar_poly(struct apuntador **poly3, int e);
  663. float eval_poly(struct apuntador *poly1,float x);
  664. float factorial(int);
  665.  
  666.  
  667. int seleccion_menu(void);
  668. int i,caso,e;
  669. float c,epsilon;
  670. float coef;
  671. int exp1,fx,x0;  // SE CAMBIA EXP SOLO AQUI O EN TODOS?
  672. char n;
  673. int opcion;
  674.  
  675. main()
  676. {
  677.  presentacion();
  678.  clrscr();
  679.  for(;;)
  680. {
  681. switch(seleccion_menu())
  682. {
  683.  
  684.  
  685.  case 1:
  686.  int limite, iter=0;
  687.  float fxd,epsilon,xa,xn;
  688.  clrscr();
  689.  printf("\n Metodo de Newton Raphson (RAICES) de poly1");
  690.  printf("\n Dame el valor inicial de x0    para poly1 ==>");
  691.  scanf("%f",&x0);
  692.  printf("\n Dame el Epsilon ==>");
  693.  scanf("%f",&epsilon);
  694.  printf("\n Dame el nuemro maximo de iteraciones ==>");
  695.  scanf("%d",&limite);
  696.  der_poly(polydat1, &polyder);
  697.  printf("\n #iter----x0----------fx----------fxd----------xn");
  698.  do
  699. {
  700. xa=x0;
  701. fx=eval_poly(polydat1,xa);
  702. fxd=eval_poly(polyder,xa);
  703. xn=xa - fx/fxd;
  704. iter=iter+1;
  705. printf("\n %d   %f   %f   %f   %f",iter,xa,fx,fxd,xn);
  706. x0=xn;
  707. } while((fabs(xa-xn)>epsilon)&&(iter<=limite));
  708.  printf("\n el valor final de x es = 5f",xn);
  709.  printf("\n\n");
  710.  pausa();
  711.  pausa();
  712.  pausa();
  713.  break;
  714.  
  715.  
  716.  case 2:
  717. clrscr();  
  718.        iniciapoly();
  719. do
  720.  {     do
  721.  {
  722. printf("\n Dame el valor del coeficiente del poly 1 ==> ");
  723. scanf("%f",&c);
  724. } while (c == 0);
  725.  
  726. printf("\n Dame el valor del exponente del poly 1   ==> ");
  727. scanf("%d",&e);
  728. insert_lista(&polydat1,c,e);
  729. printf("\n Desea otro termino (s/n) ? ==> ");
  730. opcion=getche();
  731.  }  while((opcion==115) || (opcion==83));
  732.  imprime(polydat1);
  733.  printf("\n\n");
  734.  do
  735. {
  736. do
  737.  {
  738. printf("\n Dame el valor del coeficiente del poly 2 ==> ");
  739. scanf("%f",&c);
  740. } while (c == 0);
  741. printf("\n Dame el valor del exponente de poly 2    ==> ");
  742. scanf("%d",&e);
  743. insert_lista(&polydat2,c,e);
  744. printf("\n Desea otro termino (s/n) ? ==> ");
  745. opcion=getche();
  746. }  while((opcion==115) || (opcion==83));
  747. imprime(polydat2);
  748. pausa();
  749. break;
  750.  case 3:
  751. polysum1=polydat1;
  752. polysum2=polydat2;
  753. suma_poly(polysum1,polysum2,&polysuma);
  754. imprime(polysuma);
  755. pausa();
  756. break;
  757.  case 4:
  758. polyfac1=polydat1;
  759. polyfac2=polydat2;
  760. multy_poly(polyfac1,polyfac2,&polyprod);
  761. imprime(polyprod);
  762. pausa();
  763. break;
  764.  case 5:
  765. polymin=polydat1;
  766. polysus=polydat2;
  767. resta_poly(polymin,polysus,&polyresta);
  768. imprime(polyresta);
  769. pausa();
  770. break;
  771.  case 6:
  772. polyder = polydat1;
  773. der_poly(polydat1,&polyder);
  774. printf("Derivada:\n");
  775. imprime(polyder);
  776. pausa();
  777. break;
  778.  case 7:
  779. printf("\ Fin del Programa");
  780. exit(0);
  781. default:
  782. printf("\n Operacion no valida");
  783. //return (0);
  784.  
  785.  case 8:
  786. fx=eval_poly(polydat1,x0);
  787. break;
  788.  case 9:
  789.  
  790. break;
  791.  case 10:
  792. clrscr();
  793. printf("\n Dame el valor del exponente del termino a borrar de poly1 ==> ");
  794. scanf("%d",&e);
  795. borrar_poly(&polydat1,e);
  796. imprime(polydat1);
  797. printf("\n\n");
  798. pausa();
  799. break;
  800.  
  801.  
  802.  
  803.  case 11:
  804. struct apuntador *fx;
  805. fx=polydat1;
  806. float a,b,c,it_limit,fa,fb,fc;
  807. int it=0;
  808. while(1)
  809. {//0
  810. clrscr();
  811. printf("\n Metodo de la biseccion (PARA RAICES) de poly1");
  812. printf("\n dar la cota inferior a = ?");
  813. scanf("%f",&a);
  814. printf("\n dar la cota superior b = ?");
  815. scanf("%f",&b);
  816. printf("\n Dar el epsilon ==> ?");
  817. scanf("%f",&epsilon);
  818. printf("\n Dar el limite de iteraciones =? ");
  819. scanf("%f",&it_limit);
  820. printf("\n It.--a-----b-----c-----f(a)-----f(c)-----abs(f(c)-f(a))/2");
  821. fa= eval_poly(fx,a);
  822. fb= eval_poly(fx,b);
  823. if((fa*fb)>0)
  824.  {//1
  825. printf("\n La solucion no esta entre a..b ya que f(a) f(b)>0 \n");
  826.  } //-1
  827. else
  828.  while(1)
  829. {//2
  830. it=it+1;
  831. c=(a+b)/2;
  832. fc=eval_poly(fx,c);
  833. printf("\n %3d  %10.6f  %10.6f  %10.6f  %10.6f  %10.6f",it,a,c,b,fa,fc);
  834. printf("\n %14.8f \n",fabs((fb-fa)/2));
  835. pausa();
  836. if(it>it_limit)
  837. break;
  838. if(fabs(c-a)<epsilon)
  839. break;
  840. if(fa*fc<=0)
  841.  { b=c; fb=fc; }
  842. else
  843.  { a=c; fa=fc; }
  844. }//-2
  845. if(it<=it_limit)
  846.  printf("\n Tolerancia satisfecha");
  847. if(it>it_limit)
  848.  printf("\n limite exedido de iteraciones");
  849.  printf("\n el resultado final de x es =%g \n",c);
  850.  printf("\n\n");
  851.  
  852.  pausa();
  853.  pausa();
  854.  }//0
  855. break;
  856.  
  857. case 12:
  858. struct apuntador *fsen=NULL;
  859. int t,expo,signo;
  860. double coefi,x,ter;
  861. double suma=0;
  862. double vfsen;
  863. clrscr();
  864. printf("\n Dar el valor de terminos: ");
  865. scanf("%d",&t);
  866. printf("\n Dar el valor de X: ");
  867. scanf("%f",&x);
  868. x=x*3.1416/180;
  869. printf("\n #ter sig  exp    coefi        ter         suma");
  870. for(int ni=0;ni<t;ni++)
  871.  {
  872. signo=pow(-1,ni);
  873. expo=2*ni+1;
  874. coefi=signo/factorial(expo);
  875. insert_lista(&fsen,coefi,expo);
  876. ter=coefi*pow(x,expo);
  877. suma=suma+ter;
  878. printf("\n\n %2d   %2d   %2d  %10.8f  %10.8f  %10.8f",ni+1,signo,expo,coefi,ter,suma);
  879.  }
  880. printf("\n\n\n El valor sel seno con sumatoria es : %14.12f\n\n",suma);
  881. getche();
  882. imprime(fsen);
  883. vfsen=eval_poly(fsen,x);
  884. printf("\n\n El valor del seno con polinomio es : %14.12f",vfsen);
  885. getche();
  886. polydat1=fsen;
  887. printf("\n\n");
  888. pausa();
  889. break;
  890.  
  891. case 13:
  892. struct apuntador *fsinhmu=NULL;
  893.  
  894.         int te,expon,sign;
  895. double coefic,xi,termin,dn;
  896. double sumas=0;
  897. double vfsinhmu;
  898.  
  899.         clrscr();
  900. printf("\n Dar el valor de terminos: ");
  901. scanf("%d",&te);
  902. printf("\n Dar el valor de X: ");
  903. scanf("%f",&xi);
  904. xi=xi*3.1416/180;
  905. printf("\n #Term Signo  Exp   Coeficiente   Termino      Suma");
  906. for(int n=0;n<te;n++)
  907.  {
  908. sign=pow(-1,n);
  909. expon=2*n+1;
  910. dn=2*n;
  911. coefic=(sign*factorial(dn))/(pow(4,n)*pow(factorial(n),2)*expon);
  912. insert_lista(&fsinhmu,coefic,expon);
  913. termin=coefic*pow(xi,expon);
  914. sumas=sumas+termin;
  915. printf("\n\n   %2d    %2d   %2d    %10.8f   %10.8f   %10.8f",n+1,sign,expon,coefic,termin,sumas);
  916.  }
  917. printf("\n\n\n El valor sel seno con sumatoria es : %14.12f\n\n",sumas);
  918. getche();
  919. imprime(fsinhmu);
  920. vfsinhmu=eval_poly(fsinhmu,xi);
  921. printf("\n\n El valor del seno con polinomio es : %14.12f",vfsinhmu);
  922. getche();
  923. polydat1=fsinhmu;
  924. printf("\n\n");
  925. pausa();
  926. break;
  927.  
  928. }
  929. }
  930. }
  931.  
  932. seleccion_menu(void)
  933. {
  934. char s[80];
  935. int x;
  936. clrscr();
  937. printf("\n\n          OPERACIONES DE POLINOMIOS:");
  938. printf("\n\n\n             1 ) Metodo de Newton Rhapson \n");
  939. printf("                   2 ) Crear polinomio. \n");
  940. printf("                   3 ) Suma. \n");
  941. printf("                   4 ) Multiplicacion. \n");
  942. printf("                   5 ) Resta. \n");
  943. printf("                   6 ) Derivada. \n");
  944. printf("                   7 ) Salir. \n");
  945. printf("                   8 ) Evaluar polyn(x). \n");
  946. printf("                   9 ) Modificar termino de polinomio.\n");
  947. printf("                   10 ) Borrar algun termino. \n");
  948. printf("                   11 )  Metodo de Biseccion \n");
  949. printf("                   12 )  Genera funcion Seno de Taylor \n");
  950. printf("                   13 )  Genera funcion SenoHyperbolico Inverso \n");
  951. do
  952. {
  953. printf("                                   OPCION ==> ");
  954. gets(s);
  955. x=atoi(s);
  956. }  while (x<0 || x>14);
  957. return (x);
  958. }
  959.  
  960. void pausa(void)
  961. {
  962. printf("\n Pulsar cualquier tecla para continuar...");
  963. getch();
  964. }
  965.  
  966. void iniciapoly(void)
  967. {
  968. polydat1=NULL;
  969. polydat2=NULL;
  970. polysum1=NULL;
  971. polysum2=NULL;
  972. polysuma=NULL;
  973. polymin=NULL;
  974. polysus=NULL;
  975. polyres=NULL;
  976. polyfac1=NULL;
  977. polyfac2=NULL;
  978. polyprod=NULL;
  979. polynum=NULL;
  980. polyden=NULL;
  981. polycos=NULL;
  982. polyres=NULL;
  983. polyresta=NULL;
  984. polyder=NULL;
  985. }
  986.  
  987. void insert_lista(struct apuntador **poly, float coefi, int expo)
  988. { //0
  989. struct apuntador *nuevo, *aux,*ant;
  990. int band=0;
  991. nuevo=(struct apuntador *) malloc (sizeof(nodo));
  992. if(nuevo == NULL)
  993. {//1
  994. printf("MEMORIA AGOTADA \n");
  995. return;
  996. }//-1
  997. nuevo->coef=coefi;
  998. nuevo->exp1=expo;
  999. nuevo->siguiente=NULL;
  1000. if(*poly==NULL)
  1001. *poly=nuevo;
  1002. else
  1003. {//-2
  1004. aux=*poly;
  1005. if(aux->exp1 < expo)
  1006. { //3
  1007. nuevo->siguiente=*poly;
  1008. *poly=nuevo;
  1009. }//-3
  1010. else //EN OTRSOS CASOS
  1011. {//4
  1012. while((aux)&&(band))
  1013.  {//5
  1014. if(aux->exp1==expo)
  1015.  {//6 PARA TERMINO CON IGUAL EXPONENTE
  1016. aux->coef=aux->coef+coefi;
  1017. delete(nuevo); // O ES "if(aux->coef==0)"
  1018. band=1;
  1019.  }//-6
  1020. else //PARA EL CASO: aux->exp1>expo
  1021.  {//7
  1022. if((aux->siguiente!= NULL)&&(expo>aux->siguiente->exp1))
  1023. {//8
  1024.  nuevo->siguiente=aux->siguiente;
  1025.  aux->siguiente=nuevo;
  1026.  band=1;
  1027. }//-8
  1028. else
  1029. {//9
  1030.  if(aux->siguiente==NULL)
  1031. {//10
  1032. aux->siguiente=nuevo;
  1033. band=1;
  1034. }//-10
  1035.  else
  1036. ant=aux;
  1037. aux=aux->siguiente;
  1038. }//-9
  1039.  }//-7
  1040.  }//-5
  1041. }//-4
  1042. }
  1043. }//-0
  1044.  
  1045. void imprime(struct apuntador *poly)
  1046. {
  1047. while(poly)
  1048. {
  1049. printf("\n\n Coeficiente : %f \n",poly->coef);
  1050. printf(" Exponente   : %i",poly->exp1);
  1051. poly=poly->siguiente;
  1052. }
  1053. }
  1054.  
  1055. void suma_poly(struct apuntador *poly1, struct apuntador *poly2,
  1056. struct apuntador **poly3)
  1057. {
  1058. float suma;
  1059. struct apuntador *primero;
  1060. primero = NULL;
  1061. suma=0;
  1062. while((poly1 != NULL) && (poly2 != NULL))
  1063. {
  1064. if (poly1->exp1 == poly2-> exp1)
  1065. {
  1066. suma=poly1->coef + poly2->coef;
  1067. if(suma !=0)
  1068. {
  1069. insert_lista(&primero,suma,poly1->exp1);
  1070. }
  1071. poly1=poly1->siguiente;
  1072. poly2=poly2->siguiente;
  1073. }
  1074. else
  1075. if(poly1->exp1 > poly2->exp1)
  1076. {
  1077. insert_lista(&primero,poly1->coef,poly1->exp1);
  1078. poly1=poly1->siguiente;
  1079. }
  1080. else
  1081. {
  1082. insert_lista(&primero,poly2->coef,poly2->exp1);
  1083. poly2=poly2->siguiente;
  1084. }
  1085. suma=0;
  1086. }
  1087. while(poly1 != NULL)
  1088. {
  1089. insert_lista(&primero,poly1->coef,poly1->exp1);
  1090. poly1=poly1->siguiente;
  1091. }
  1092. while(poly2 != NULL)
  1093. {
  1094. insert_lista(&primero,poly2->coef,poly2->exp1);
  1095. poly2=poly2->siguiente;
  1096. }
  1097. *poly3 = primero;
  1098. }
  1099.  
  1100. void multy_poly(struct apuntador *poly1, struct apuntador *poly2,
  1101. struct apuntador **poly3)
  1102. {
  1103. struct apuntador *primero;
  1104. float multy;
  1105. int sum;
  1106. struct apuntador *p, *q, *aux1, *aux2;
  1107.  
  1108. primero = NULL;
  1109. *poly3=NULL;
  1110. multy=1;
  1111. sum=0;
  1112. while(poly2 != NULL)
  1113. {
  1114. p=poly1;
  1115. while(p!=NULL)
  1116. {
  1117. multy=p->coef *poly2->coef;
  1118. sum=p->exp1 + poly2->exp1;
  1119. if(multy != 0)
  1120. {
  1121. insert_lista(&primero,multy,sum);
  1122. p=p->siguiente;
  1123. }
  1124. else
  1125. {
  1126. insert_lista(&primero,p->coef,p->exp1);
  1127. p=p->siguiente;
  1128. poly2=poly2->siguiente;
  1129. }
  1130. multy=1;
  1131. }
  1132. poly2=poly2->siguiente;
  1133. }
  1134. q = primero;
  1135. while(q)
  1136. {
  1137. if(q->exp1==q->siguiente->exp1)
  1138. {
  1139. q->coef=q->coef + q->siguiente->coef;
  1140. q->siguiente=q->siguiente->siguiente;
  1141. }
  1142. else
  1143. q=q->siguiente;
  1144. }
  1145. *poly3=primero;
  1146. }
  1147.  
  1148. void resta_poly(struct apuntador *poly1, struct apuntador *poly2,
  1149. struct apuntador **poly3)
  1150. {
  1151.    float resta;
  1152.    struct apuntador *primero;
  1153. primero = NULL;
  1154. resta= 0;
  1155.    while ((poly1 != NULL) && (poly2 != NULL))
  1156. {
  1157.  if (poly1->exp1 == poly2->exp1)
  1158. {
  1159. resta= poly1->coef - poly2->coef;
  1160. if (resta != 0) {
  1161. insert_lista (&primero, resta, poly1->exp1); }
  1162. poly1= poly1->siguiente;
  1163. poly2= poly2->siguiente;
  1164. }
  1165.  else
  1166. if (poly1->exp1 > poly2->exp1)
  1167. {
  1168. insert_lista (&primero, poly1->coef, poly1->exp1);
  1169. poly1= poly1->siguiente;
  1170. }
  1171. else
  1172. {
  1173. insert_lista (&primero, poly2->coef, poly2->exp1);
  1174. poly2= poly2->siguiente;
  1175. }
  1176. resta= 0;
  1177. }
  1178.  
  1179. while (poly1 != NULL)
  1180. {
  1181. insert_lista (&primero, poly1->coef, poly1->exp1);
  1182. poly1= poly1->siguiente;
  1183. }
  1184.  
  1185.    while (poly2 != NULL)
  1186. {
  1187. insert_lista (&primero, -poly2->coef, poly2->exp1);
  1188.   poly2= poly2->siguiente;
  1189. }
  1190.      *poly3 = primero;
  1191. }
  1192.  
  1193. void borrar_poly(struct apuntador **poly, int expo)
  1194. {
  1195. // aqui va el codigo correspondiente
  1196. }
  1197.  
  1198. void div_poly(struct apuntador *polynume, struct apuntador *polydeno,
  1199. struct apuntador **polycoci, struct apuntador **polyresi)
  1200. {
  1201.  
  1202. }
  1203.  
  1204. void der_poly(struct apuntador *poly1,struct apuntador **poly3)
  1205. {
  1206. struct apuntador *primero=NULL;
  1207. float co=0;
  1208. int ex=0;
  1209.  while((poly1!=NULL)&&(poly1->exp1!=0))
  1210. {
  1211. co=poly1->coef*poly1->exp1;
  1212. ex=poly1->exp1-1;
  1213. insert_lista(&primero,co,ex);
  1214. poly1=poly1->siguiente;
  1215. }
  1216. }
  1217.  
  1218. float eval_poly(struct apuntador *poly1, float ev)
  1219. {
  1220.  float res2;
  1221.  res2=0;
  1222.  while(poly1)
  1223. {
  1224. res2=res2+poly1->coef*pow(ev,poly1->exp1);
  1225. poly1=poly1->siguiente;
  1226. }
  1227. return (res2);
  1228. }
  1229.  
  1230. void presentacion(void)
  1231. {
  1232. char c[1];
  1233. clrscr();
  1234. printf("\n\n                      PROGRAMA POLINOMIO \n\n");
  1235. printf("          REALIZA LA SUMA, RESTA, MULTIPLICACION Y DIVISION \n\n");
  1236.  
  1237. }
  1238.  
  1239. float factorial(int n)
  1240.  {
  1241.   int k;
  1242.   float f=1;
  1243.   for(k=1;k<=n;k++)
  1244.      f=f*k;
  1245.   return(f);
  1246.  }
  1247.  


En línea

amchacon


Desconectado Desconectado

Mensajes: 1.211



Ver Perfil
Re: Menú con funciones, no se si lo esta haciendo bien.
« Respuesta #1 en: 10 Marzo 2013, 12:01 pm »

Lo has copiado dos veces : p

Te diré una cosa sin acritud, no me gusta el estilo de programación de tu profesor/tú (Variables globales, uso de librerías innecesarias o no estándares, void main...). Muchas de esas cosas son fuentes de errores, tampoco me gusta esta función:

Código
  1. void presentacion(void)
  2. {
  3. char c[1];
  4. clrscr();
  5. printf("\n\n                      PROGRAMA POLINOMIO \n\n");
  6. printf("          REALIZA LA SUMA, RESTA, MULTIPLICACION Y DIVISION \n\n");
  7.  
  8. }
Para dos printfs... Luego pones operaciones muy largas en el main *_*

Uso de funciones de librerías no estándares como esta:
Código
  1. clrscr();

Esto es una función exclusiva de turboland, un IDE de hace casi 8 AÑOS. Habiendo opciones que funciona en todos los IDE (como system("CLS"); ) no entiendo porque se usan funciones no estándares y además anticuadas...

Si no vais a programar en multi-archivo, iría bien ordenar las funciones por criterios lógicos. Por ejemplo, todas las funciones que devuelvan int juntas y ordenadas alfabeticamente...

Luego hay otras curiosidades como esta:

Código
  1. void insert_lista(struct apuntador **poly, float coefi, int expo)
  2. { //0
  3. struct apuntador *nuevo, *aux,*ant;
  4. int band=0;
  5.         nuevo=(struct apuntador *) malloc (sizeof(nodo));
  6. if(nuevo == NULL)
  7. {//1
  8. printf("MEMORIA AGOTADA \n");
  9. return;
  10. }//-1

Intenta reservar memoria, si está agotada manda un aviso y termina la función. Bien hasta ahí perfecto, el problema es que cuando llamas la función:
Código
  1. insert_lista(&polydat2,c,e);
  2. printf("\n Desea otro termino (s/n) ? ==> ");
  3. opcion=getche();
  4. }  while((opcion==115) || (opcion==83));
  5. imprime(polydat2);
  6. pausa();

No tienes forma de saber si insert_lista termino con exito o no, si no se termino con exito debería salir del bucle y saltarse el "imprime" (incluso se podría aceptar salir del programa).

Funciones como getche() podrían sustituirse por getchar(). Así te ahorrarías incluir las conio.h que es una librería no estándar que solo funciona en Windows (pudiendo hacer el programa multiplataforma, porque hacerlo solo para Windows?).

Main debe ser int main() y debe devolver un return 0; al final:

Citar
5) void main();

Seguramente para justificar esto habría que decir que el estándar dice que void no puede ser el valor de retorno del main, lo cual es verdad, pero no siempre es suficiente. Sobretodo considerando que muchas veces en los libros el void main dice presente.

No voy a extenderme mucho con esto ya que voy a dejar los links necesarios para el que quiera entender porque sucede, pero como base comprendamos esto:
 
-Devolver un valor void es perder la garantia que un valor de retorno distinto de 0 implica un error, lo cual es malo tanto para el SO como para el determinado programa que pueda estar llamando a tu código.

-Esta mal acorde al estándar.

-Puede que tu programa no funcione correctamente.

Los errores pueden depender de los mecanismos de retorno o la arquitectura especifica en la cual estemos. Pero por supuesto, si elegimos un lenguaje de alto nivel como lo es C o C++, es para no tener que preocuparnos por esos asuntos.

En conclusión, el que quiera entender el " por que", leer los siguientes links.

Links:

http://www.eskimo.com/~scs/readings/voidmain.960823.html
http://home.att.net/~jackklein/ctips01.html#int_main
http://users.aber.ac.uk/auj/voidmain.shtml

Sería adecuado poner comentarios en los case para saber que opción estamos trabajando:

Código
  1. switch(seleccion_menu())
  2. {
  3.  
  4.  
  5.  case 1: // METODO DE NEWTON RAPHSON
  6.  
  7. // clrscr();
  8.  printf("\n Metodo de Newton Raphson (RAICES) de poly1");

Tampoco se deben usar variables globales:
Código
  1. int i,caso,e;
  2. float c,epsilon;
  3. float coef;
  4. int exp1,fx,x0;  // SE CAMBIA EXP SOLO AQUI O EN TODOS?
  5. char n;
  6. int opcion;

Primero porque permanecen todo el rato en memoria, segundo porque es una fuente de errores muy grandes... No me malinterpetres, hay usos de las variables globales legítimos pero nunca para pasar datos a funciones:
https://www.youtube.com/watch?v=0QXkRD3fzVQ

El exp1 se cambia ahí salvo que esté "enmascarado". Y con enmascarado me refiero a algo de este estilo:
Código
  1. int exp1;
  2. ...
  3. void Funcion()
  4. {
  5.   int exp1; // Esta variable exp1 "enmascara" a la otra hasta que termina la funcion
  6. }

Pasando a otra cosa. Aquí hay un error en el Switch:
Código
  1. case 7:
  2. printf("\ Fin del Programa");
  3. exit(0);
  4. default:
  5. printf("\n Operacion no valida");
  6. //return (0);
  7.  
  8.  case 8:
  9. fx=eval_poly(polydat1,x0);
  10. break;

Si insertas un numero no valido se ejecutara el default... Y como no has puesto break se ejecutara también el caso 8. Lo ideal esque pongas el default al final.

Por ultimo una cosa menor:

Código
  1. xi=xi*3.1416/180;

Para ahorrarle una operación a la máquina podrías definir una constante con su valor:

Código
  1. #define Conversion 0.0174
  2. ...
  3. xi = xi*Conversion;

Evidentemente, no te estoy echando en cara todo esto, yo era peor en tus tiempos :silbar:. Pero lo de tu profesor tiene tela...

Lo del seno no lo he podido comprobar, tendría que revisar mis apuntes de mates haber como se hacia el seno de Taylor  :silbar:


« Última modificación: 10 Marzo 2013, 12:05 pm por amchacon » En línea

Por favor, no me manden MP con dudas. Usen el foro, gracias.

¡Visita mi programa estrella!

Rar File Missing: Esteganografía en un Rar
ivanel93

Desconectado Desconectado

Mensajes: 10


Ver Perfil
Re: Menú con funciones, no se si lo esta haciendo bien.
« Respuesta #2 en: 10 Marzo 2013, 19:43 pm »

gracias por resolver unas cuantas dudas ja si he preguntado a amigos y se quedaron asi de ?? me mencionaron que el código es muy antaño, pero no me definieron cosas como las que has mencionado si mi profe es malo es ing. en electrónica, no en sistemas, programación o sus derivados, y que se pirateo el codigo, nos ha dado correcciones de ese código 3 veces y la ultima la ha dado incompleta, por lo que del tema no se si mi programa lo este haciendo correcto del modo que deberia gracias pero sigo sin entender lo de las listas LSED
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines