SoloCodigo

Programación General => C/C++ => Mensaje iniciado por: eruelas en Miércoles 24 de Septiembre de 2008, 18:57

Título: PROBLEMA PARA KALKULAR
Publicado por: eruelas en Miércoles 24 de Septiembre de 2008, 18:57
TENGO UN PROGRAMA K ME TIENE K KALKULAR EL FACTORIAL DE CIERTO NUMERO PERO ESK ME SALE UN ERROR DICIENDO K LA DECLARACION ES OBSOLTA EN K PUEDE ESTAR MAL?? GRACIAS DE ANTEMANO  AKA EL KODIGO
Código: Text
  1. #include<conio.h>
  2. #include<stdio.h>
  3. long int fact(int x);
  4. void main()
  5. {
  6. int r,x;
  7.     printf("Introduce un numero[que no sea menor a 2]:");
  8.     scanf("%i",&r);
  9. if (r<2)
  10.     printf("Error el numero no debe ser menor a 2");
  11.     fact(x);
  12. }
  13. long int fact()
  14. {
  15. int x;
  16.     for (int i=0;i<x;i++)
  17.         for(int j=0;j<x;j--)
  18.         {
  19.         printf("%i",x);
  20.         return x;
  21.         }
  22.         getch();
  23.         }
  24.  
  25.  
  26.  
  27.  
Título: Re: PROBLEMA PARA KALKULAR
Publicado por: AnimaSubtilis en Miércoles 24 de Septiembre de 2008, 19:40
Cita de: "CoNtRoLcD"
TENGO UN PROGRAMA K ME TIENE K KALKULAR EL FACTORIAL DE CIERTO NUMERO PERO ESK ME SALE UN ERROR DICIENDO K LA DECLARACION ES OBSOLTA EN K PUEDE ESTAR MAL?? GRACIAS DE ANTEMANO AKA EL KODIGO
Código: Text
  1. #include<conio.h>
  2. #include<stdio.h>
  3. long int fact(int x);
  4. void main()
  5. {
  6. int r,x;
  7.     printf("Introduce un numero[que no sea menor a 2]:");
  8.     scanf("%i",&r);
  9. if (r<2)
  10.     printf("Error el numero no debe ser menor a 2");
  11.     fact(x);
  12. }
  13. long int fact()
  14. {
  15. int x;
  16.     for (int i=0;i<x;i++)
  17.         for(int j=0;j<x;j--)
  18.         {
  19.         printf("%i",x);
  20.         return x;
  21.         }
  22.         getch();
  23.         }
  24.  
  25.  
  26.  
  27.  

en primer lugar define una funcion con un parametro tipo entero..
y al momento de hacer la definido no esta definido

segundo

Código: Text
  1.  
  2. for(int j=0;j<x;j--)
  3.         {
  4.         printf("%i",x);
  5.         return x;
  6.         }
  7.  
  8.  

la verdad  :P  no me acuerdo como se saca el factorial pero ese ciclo al revez..?? :wacko:

y por ultimpo returna un valor en ciclo
solo lo va hacer una vez y ya para de contar..

espero que le sea de ayuda

taluego....
Título: Re: PROBLEMA PARA KALKULAR
Publicado por: AnimaSubtilis en Miércoles 24 de Septiembre de 2008, 19:40
Cita de: "CoNtRoLcD"
TENGO UN PROGRAMA K ME TIENE K KALKULAR EL FACTORIAL DE CIERTO NUMERO PERO ESK ME SALE UN ERROR DICIENDO K LA DECLARACION ES OBSOLTA EN K PUEDE ESTAR MAL?? GRACIAS DE ANTEMANO AKA EL KODIGO
Código: Text
  1. #include<conio.h>
  2. #include<stdio.h>
  3. long int fact(int x);
  4. void main()
  5. {
  6. int r,x;
  7.     printf("Introduce un numero[que no sea menor a 2]:");
  8.     scanf("%i",&r);
  9. if (r<2)
  10.     printf("Error el numero no debe ser menor a 2");
  11.     fact(x);
  12. }
  13. long int fact()
  14. {
  15. int x;
  16.     for (int i=0;i<x;i++)
  17.         for(int j=0;j<x;j--)
  18.         {
  19.         printf("%i",x);
  20.         return x;
  21.         }
  22.         getch();
  23.         }
  24.  
  25.  
  26.  
  27.  

en primer lugar define una funcion con un parametro tipo entero..
y al momento de hacer la funcion no esta definido

segundo

Código: Text
  1.  
  2. for(int j=0;j<x;j--)
  3.         {
  4.         printf("%i",x);
  5.         return x;
  6.         }
  7.  
  8.  

la verdad  :P  no me acuerdo como se saca el factorial pero ese ciclo al revez..?? :wacko:

y por ultimpo returna un valor en ciclo
solo lo va hacer una vez y ya para de contar..

espero que le sea de ayuda

taluego....
Título: Re: PROBLEMA PARA KALKULAR
Publicado por: eruelas en Jueves 25 de Septiembre de 2008, 06:03
bueno gracias de todas maneras pero ps ya solucine mi problema se te agradece
Título: Re: PROBLEMA PARA KALKULAR
Publicado por: m0skit0 en Jueves 25 de Septiembre de 2008, 09:25
La función más sencilla para calcular un factorial:

Código: C
  1.  
  2. /* Sólo números naturales (>=0) */
  3. long factorial(int n)
  4. {
  5.     if(n==0)
  6.         return 1;
  7.     else
  8.         return n*factorial(n-1);
  9. }
  10.  
  11.