1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Probelm to declare a function

Discussion in 'C' started by aniknaruto, Jan 24, 2010.

  1. aniknaruto

    aniknaruto New Member

    Joined:
    Jan 24, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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 .
     
    Last edited by a moderator: Jan 25, 2010
  2. kiddo

    kiddo New Member

    Joined:
    Apr 11, 2009
    Messages:
    65
    Likes Received:
    1
    Trophy Points:
    0
    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.
     

Share This Page