Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Probelm to declare a function (http://www.go4expert.com/forums/probelm-declare-function-t20749/)

aniknaruto 25Jan2010 01:47

Probelm to declare a function
 
Please hepl me about how to declare a function in dev-c++.I did it as following but it didn't work .
Code:

#include<stdio.h>
#include<stdlib.h>
 fac(int p);
void  main()
{ int a,d,e;
scanf("%d",&a);
scanf("%d",&d);
e=fac(a)/(fac(d)*fac(a-d));
printf("%d",e);
return 0;
system("pause");

      }
      fac(int p)
      { int p,b,c;
      for(c=1;c<=p;c++){b=b*c;}
      return b;
                        }
                       
     
                       
              }

I used dev-c++ 4.9.9.2 .

kiddo 25Jan2010 14:49

Re: Probelm to declare a function
 
Code:

#include<stdio.h>
#include<stdlib.h>

int fac(int p);

int main(){
  int a,d,e;
  scanf("%d",&a);
  scanf("%d",&d);
  e=fac(a)/(fac(d)*fac(a-d));
  printf("%d",e);
  return 0;
  system("pause");
}

int fac(int p){
 int p,b,c;
 b = 1;
 for(c=1;c<=p;c++){
  b=b*c;
 }
 return b;
}

I think you make so many error in your code. If your function will return integer, you must give the int to the function data type. It shows the data type it will return.

You cannot use void main in dev-cpp.

To make factorial function, you can try the recursive method.
Find out.


All times are GMT +5.5. The time now is 16:41.