Results 1 to 8 of 8

Thread: c++ exp

  1. #1
    hasib ahmed's Avatar
    hasib ahmed is offline Advance Member
    Last Online
    12th November 2022 @ 11:45 PM
    Join Date
    08 Sep 2008
    Location
    rawalpindi
    Age
    34
    Gender
    Male
    Posts
    850
    Threads
    106
    Credits
    83
    Thanked
    15

    Default c++ exp

    #include <iostream.h>
    #include <conio.h>
    long fact(int m);
    void main()
    {
    clrscr();
    int a;
    long res;
    cout<<"enter the intiger=";
    cin>>a;
    res=long fact(int a);
    cout<<"the factorial is = "<<res;
    getch();
    }
    long fact(int a)
    {
    int r, counter=1;
    for(int i=1;i<=a;i++)
    r=counter*i;
    return r;
    }
    iss code ma koi galti hai kia? compiler expression error deta hai calling statment par
    Last edited by hasib ahmed; 4th December 2011 at 03:49 PM. Reason: values change
    ma ishq-e-kainaat ma zanjeer ho saku
    mujh ko hisar-e-zaat ke shar se rahai de


  2. #2
    hasib ahmed's Avatar
    hasib ahmed is offline Advance Member
    Last Online
    12th November 2022 @ 11:45 PM
    Join Date
    08 Sep 2008
    Location
    rawalpindi
    Age
    34
    Gender
    Male
    Posts
    850
    Threads
    106
    Credits
    83
    Thanked
    15

    Default

    help me please

  3. #3
    Zeeshanef's Avatar
    Zeeshanef is offline Advance Member
    Last Online
    28th December 2023 @ 02:18 PM
    Join Date
    30 Mar 2006
    Location
    Great Pakistan
    Gender
    Male
    Posts
    846
    Threads
    12
    Credits
    1,456
    Thanked
    46

    Default

    1. Function Declaration mein error hay Sahi ye hay (long fact(int);)
    2. Function ic tarha call hoga (res=fact(int a);)
    3. Logical error factorial nikalne ke lye loop upper se nichay chalti he, jis tarha nichay code mein hay.

    Code:
    #include <iostream.h>
    #include <conio.h>
    
    long fact(int);
    
     void main()
     {
     clrscr();
     int a;
     long res;
     cout<<"Enter the Integer:? ";
     cin>>a;
     res=fact(a);
     cout<<"The factorial of "<< a <<" is = "<<res;
     getch();
     }
    
    //Functions Definition
     long fact(int a)
     {
     int counter=1;
     for(int i=a;i>0;i--)
    	counter=counter*i;
     return counter;
     }

  4. #4
    Salluhassan's Avatar
    Salluhassan is offline Senior Member+
    Last Online
    10th February 2020 @ 06:32 PM
    Join Date
    02 Aug 2010
    Location
    Lahore
    Gender
    Male
    Posts
    2,241
    Threads
    29
    Credits
    114
    Thanked
    217

    Default

    Quote hasib ahmed said: View Post
    #include <iostream.h>
    #include <conio.h>
    long fact(int m);
    void main()
    {
    clrscr();
    int a;
    long res;
    cout<<"enter the intiger=";
    cin>>a;
    res=long fact(int a);
    cout<<"the factorial is = "<<res;
    getch();
    }
    long fact(int a)
    {
    int r, counter=1;
    for(int i=1;i<=a;i++)
    r=counter*i;
    return r;
    }
    iss code ma koi galti hai kia? compiler expression error deta hai calling statment par

    res=long fact(int a); <<< han is line may "long" say declare q kiya , remove it

  5. #5
    sayhellotoit's Avatar
    sayhellotoit is offline Senior Member
    Last Online
    23rd September 2017 @ 07:51 PM
    Join Date
    01 May 2009
    Posts
    1,003
    Threads
    5
    Credits
    53
    Thanked
    127

    Default

    Function call kertay hovay sirf function ka naam aur parameter.
    res=long fact(int a);
    ki jaga
    res=fact(a);

    function kay ander akhri 2 lines:
    r=counter*i;
    return r;

    ki jaga

    coutner=counter*i;
    return counter;

    #include <iostream.h>
    #include <conio.h>
    long fact(int m);
    void main()
    {
    clrscr();
    int a;
    long res;
    cout<<"enter the intiger=";
    cin>>a;
    res=fact(a);
    cout<<"the factorial is = "<<res;
    getch();
    }
    long fact(int a)
    {
    int counter=1;
    for(int i=1;i<=a;i++)
    counter=counter*i;
    return counter;
    }

  6. #6
    hasib ahmed's Avatar
    hasib ahmed is offline Advance Member
    Last Online
    12th November 2022 @ 11:45 PM
    Join Date
    08 Sep 2008
    Location
    rawalpindi
    Age
    34
    Gender
    Male
    Posts
    850
    Threads
    106
    Credits
    83
    Thanked
    15

    Default

    Quote Zeeshanef said: View Post
    1. Function Declaration mein error hay Sahi ye hay (long fact(int);)
    2. Function ic tarha call hoga (res=fact(int a);)
    3. Logical error factorial nikalne ke lye loop upper se nichay chalti he, jis tarha nichay code mein hay.

    Code:
    #include <iostream.h>
    #include <conio.h>
    
    long fact(int);
    
     void main()
     {
     clrscr();
     int a;
     long res;
     cout<<"Enter the Integer:? ";
     cin>>a;
     res=fact(a);
     cout<<"The factorial of "<< a <<" is = "<<res;
     getch();
     }
    
    //Functions Definition
     long fact(int a)
     {
     int counter=1;
     for(int i=a;i>0;i--)
    	counter=counter*i;
     return counter;
     }
    bro loop dono tareeqo se same kaam kare ga chahe chk kar lo?

  7. #7
    hasib ahmed's Avatar
    hasib ahmed is offline Advance Member
    Last Online
    12th November 2022 @ 11:45 PM
    Join Date
    08 Sep 2008
    Location
    rawalpindi
    Age
    34
    Gender
    Male
    Posts
    850
    Threads
    106
    Credits
    83
    Thanked
    15

    Default

    Quote sayhellotoit said: View Post
    Function call kertay hovay sirf function ka naam aur parameter.
    res=long fact(int a);
    ki jaga
    res=fact(a);

    function kay ander akhri 2 lines:
    r=counter*i;
    return r;

    ki jaga

    coutner=counter*i;
    return counter;
    yar sirf veriables change krne se kuch bi nae hota ..

  8. #8
    sayhellotoit's Avatar
    sayhellotoit is offline Senior Member
    Last Online
    23rd September 2017 @ 07:51 PM
    Join Date
    01 May 2009
    Posts
    1,003
    Threads
    5
    Credits
    53
    Thanked
    127

    Default

    Quote hasib ahmed said: View Post
    yar sirf veriables change krne se kuch bi nae hota ..
    Janab sirf variables change kernay ko nahi kaha.
    aik tu function sahi say call nahi ker rahay thay aap.
    dosra function kay ander calculations sahi nahi ker rahay thay.

    Sahi program bhi attach kia hay aur Run ker kay bhi daikha hay, bilkul sahi chal raha hay.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •