Code for finding the factorial of a no

program  for finding the factorial of a no........

hi
the following are the 2 different codes  for factorial
PARAMETERS:
  P_NUMBR TYPE I.
DATA:
  W_FACT TYPE I VALUE 1,
  W_TEMP TYPE I.
W_TEMP = P_NUMBR.
DO P_NUMBR TIMES.
  W_FACT = W_FACT * W_TEMP.
  SUBTRACT 1 FROM W_TEMP.
ENDDO.
WRITE: W_FACT.
USING MACROS
DEFINE FACTORIAL.                      " Define macro
  DO 5 TIMES.                          " Do 5 times
    IF &1 GT 5.
      EXIT.
    ELSE.
      &2 = &1 * &2.
      WRITE: /'The factorial of &1 is'(001),&2.
    ENDIF.                             " Endif
    &1 = &1 + 1.
  ENDDO.                             " Enddo
END-OF-DEFINITION.
DATA:
    w_fact TYPE I VALUE 1,             " Factorial
    w_temp TYPE I VALUE 1.             " Temp
FACTORIAL w_temp w_fact.
regards,
kiran kumar k

Similar Messages

  • Code for find the missing number in array without sorting/comparing in java

    Hi all,
    We have 1 to 100 number in an array, but one number is missing (from 1 to 100). we have to find it out without sorting or comparing of this missing number in array.
    please help me out to find the solution this query.
    regards & thanks
    Mohan Kumar
    Bangalore,
    India

    Maybe you could sum up the numbers you've got in your array and subtract the result from 5050 [the term [code](N*N+N)/2 where N is your upper bound (i.e. 100)]. You'll get the sum of all missing values (which in this case would be exactly the missing number). n.b. that you could genaeralize on that for arbitrary finite series.
    Kind Regards,

  • Need a code for finding prime no.s from 0 to 100.

    Hi,
    i need a code for finding prime no.s from 0 to 100.
    Please help me out.
    Regards,
    Santosh Kotra.

    hai santosh,
    here is an example program to find the prime number...........
    EXAMPLE:
    DATA: BEGIN OF primes OCCURS 0,
            number TYPE i,
            exp    TYPE i,
          END OF primes.
    DATA: w_mult TYPE i,
          w_limi TYPE i,
          w_prem TYPE i.
    DATA: w_outp TYPE text132.
    DATA: w_rtime TYPE i,
          w_stime TYPE p DECIMALS 3.
    DEFINE add_part.
      sy-fdpos = strlen( &1 ) + 1.
      &1+sy-fdpos(*) = &2.
      condense &1.
    END-OF-DEFINITION.
    PARAMETERS: p_numb TYPE i,                "number to check
                p_fact TYPE c AS CHECKBOX,    "display components
                p_nbpr TYPE c AS CHECKBOX.    "nb of primes
    START-OF-SELECTION.
      GET RUN TIME FIELD w_rtime.
      IF p_nbpr IS INITIAL OR p_numb LE 12000.
        PERFORM eratostene USING p_numb.
        add_part w_outp p_numb.
        READ TABLE primes WITH KEY number = p_numb.
        IF sy-subrc = 0.
          add_part w_outp 'is prime'.
        ELSE.
          IF p_fact IS INITIAL.
            add_part w_outp 'is not prime'.
          ELSE.
            add_part w_outp '='.
            w_limi = p_numb.
            LOOP AT primes WHERE exp GT 0.
              CHECK primes-number LE w_limi.
              IF w_prem GT 0.
                add_part w_outp '*'.
              ENDIF.
              IF primes-exp GT 1.
                add_part w_outp '('.
                add_part w_outp primes-number.
                add_part w_outp '^'.
                add_part w_outp primes-exp.
                add_part w_outp ')'.
              ELSE.
                add_part w_outp primes-number.
              ENDIF.
              w_limi = w_limi / ( primes-number ** primes-exp ).
              IF w_limi = 1.
                EXIT.
              ENDIF.
              w_prem = 1.
            ENDLOOP.
          ENDIF.
        ENDIF.
        WRITE: / w_outp.
        IF NOT p_nbpr IS INITIAL.
          DESCRIBE TABLE primes LINES sy-tmaxl.
          CLEAR: w_outp.
          add_part w_outp 'Number of primes:'.
          add_part w_outp sy-tmaxl.
          WRITE: / w_outp.
          SKIP.
          LOOP AT primes.
            WRITE: / primes-number.
          ENDLOOP.
        ENDIF.
      ELSE.
        PERFORM factors.
      ENDIF.
      GET RUN TIME FIELD w_rtime.
      w_stime = w_rtime / 1000000.
      SKIP.
      CLEAR: w_outp.
      add_part w_outp 'Calculation time:'.
      add_part w_outp w_stime.
      WRITE: / w_outp.
          FORM eratostene                                               *
    FORM eratostene USING in_number TYPE i.
      DATA: BEGIN OF no_primes OCCURS 0,
              number TYPE i,
            END OF no_primes.
      DATA: cnum TYPE i,
            dnum TYPE i,
            limi TYPE i,
            mult TYPE i,
            puis TYPE i,
            cmod TYPE i.
      IF NOT ( p_fact IS INITIAL AND p_nbpr IS INITIAL ).
        limi = in_number.
      ELSE.
        limi = sqrt( in_number ).
      ENDIF.
      cnum = 2.
      WHILE cnum LE limi.
        READ TABLE no_primes WITH KEY number = cnum.
        IF sy-subrc NE 0.
          primes-number = cnum.
          mult = 2.
          puis = 1.
          dnum = mult * cnum.
          WHILE dnum LE in_number.
            READ TABLE no_primes WITH KEY number = dnum.
            IF sy-subrc NE 0.
              no_primes-number = dnum.
              APPEND no_primes.
            ENDIF.
            IF NOT p_fact IS INITIAL.
              cmod = dnum MOD ( cnum ** puis ).
              IF cmod = 0.
                cmod = in_number MOD ( cnum ** puis ).
                IF cmod = 0.
                  primes-exp = puis.
                  puis = puis + 1.
                ENDIF.
              ENDIF.
            ENDIF.
            mult = mult + 1.
            dnum = mult * cnum.
          ENDWHILE.
          APPEND primes.
          CLEAR: primes.
        ENDIF.
        cnum = cnum + 1.
      ENDWHILE.
    ENDFORM.
          FORM factors                                                  *
    FORM factors.
      DATA: ex_factors TYPE string,
            mod        TYPE i,
            still      TYPE f,
            factor     TYPE i,
            exponent   TYPE i,
            square     TYPE f,
            fac_string TYPE text40,
            exp_string TYPE text40.
      IF p_numb LE 3.
        ex_factors = p_numb.
      ELSE.
        factor = 2.
        still  = p_numb.
        DO.
          CLEAR: exponent.
          mod = still MOD factor.
          WHILE mod = 0.
            exponent = exponent + 1.
            still    = still div factor.
            mod      = still MOD factor.
          ENDWHILE.
          IF exponent EQ 1.
            fac_string = factor.
            CONCATENATE ex_factors '*'  fac_string
                                   INTO ex_factors
                           SEPARATED BY space.
            CONDENSE ex_factors.
          ELSEIF exponent GT 1.
            fac_string = factor.
            exp_string = exponent.
            CONCATENATE ex_factors '* (' fac_string
                                   '^'   exp_string ')'
                                   INTO  ex_factors
                           SEPARATED BY space.
            CONDENSE ex_factors.
          ENDIF.
          factor = factor + 1.
          square = factor ** 2.
          IF square GT still.
            EXIT.
          ENDIF.
        ENDDO.
        IF still GT 1.
          CATCH SYSTEM-EXCEPTIONS convt_overflow = 1.
            fac_string = factor = still.
          ENDCATCH.
          IF sy-subrc NE 0.
            fac_string = still.
          ENDIF.
          CONCATENATE ex_factors '*' fac_string
                                INTO ex_factors
                        SEPARATED BY space.
          CONDENSE ex_factors.
        ENDIF.
        SHIFT ex_factors UP TO '*'.
        SHIFT ex_factors BY 2 PLACES.
      ENDIF.
      WRITE: / p_numb RIGHT-JUSTIFIED.
      IF ex_factors CA '*^'.
        WRITE: '=', ex_factors.
      ELSE.
        WRITE: 'is prime'.
      ENDIF.
    ENDFORM.
    HOPE THIS WILL BE HELPFULL.
    regards
    praba.

  • What is the transaction code for see the Web Services available in SAP

    Hi
    I came to know that SAP has provided its own webservices... I need some information on that... If any one has documentation on that can u please send it to me... My ID is <b>[email protected]</b>.
    What is the trasaction code for see the web services available in SAP.... Can any one help.. Please its  urgent
    Best Regards
    Ravi Shankar B
    Message was edited by:
            RaviShankar B

    Hi,
    you can find Web Services (Enterprise Services) in the Enterprise Services Workplace (ES Workplace). The ES Workplace allows you to explore, test, and use enterprise services to make enterprise SOA tangible. Here, you will find all of the currently productized enterprise services by SAP.
    Best Regards,
    Boris Mueller
    <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/developerareas/esa/esapreview">ES Workplace at SDN</a>
    <a href="http://esapreview.sap.com:82/socoview(bD1kZSZjPTgwMCZkPW1pbg==)/flddisplay.asp">ES Workplace</a>

  • Code for finding CPU utilisation for executing query

    Hi, i need code for finding CPU utilisation for executing the particular query.

    Use session tracing, then in trace file you can find cpu utilization for particular statement on each phase: parse, execute, fetch and the overall.
    Or You can use the dbms_utility.get_cpu_time (if your database is 10g) in pl/sql:
    declare
    cpt1 pls_integer;
    cpt2 pls_integer;
    cputime pls_integer;
    begin
    cpt1:=sys.dbms_utility.get_cpu_time;
    <some code here>
    cpt2:=sys.dbms_utility.get_cpu_time;
    cputime:=cpt2-cpt1;
    end;
    good luck

  • Code for displaying the elements of ArraList and HashMap

    hi..im new to java ..
    tell me the code for displaying the elements of ArraList and HashMap

    myj-ava wrote:
    wt abt displaying the elments of HashMap?plz..give clear codehey, this is not a code-giving service. This is a forum of volunteers who help others who have specific questions. I find that the greatest help is given to those who have shown that they've put in at least some effort. You have shown none. Please look at the Sun tutorials first, then come back with a specific question if anything there confuses you.

  • Relation ship code for finding manager position..

    Hi Experts,
    How to find the relationship code for finding Manager position of France and US.
    i know that
    A012 is the relationship code for France,
    What should be the relationship code for US?
    Thanks in advance.

    Hi
    If you take tables QMEL & DRAW / DRAW & QMFE
    if u have created a document in CV01N, with the object link has notification... Then you will be able to able both these tables...
    Document will be displayed...
    Both has same relationships.... you have to maintain the notification in document management system.
    Check out the linking details in SPRO - Cross-Application Components - Document Management - Control Data - Define Document types
    - Pithan

  • Where do I find the factory pin number?

    I can't find the factory installed pin number for 4gs phone. How do I find it?

    Thanks. I guess I got confused when I saw change Passcode as the second option when I had not assigned one.

  • T.code for check the Total SRS

    pls tell me t.code for match the SRS (stock requitions slip)from store  or production ?
    Thanks
    Rekha Sharma

    U can check in MB25 or in MB51.

  • Wanted to update the software now available, but it is asking for a pass code. As far as I remember in didn't put in any pass code , how do I settle this issue . Earlier updates were asking Apple ID but pass code for updating the new soft ware not known.

    Wanted to update the software now available, but it is asking for a pass code. As far as I remember in didn't put in any pass code , how do I settle this issue . Earlier updates were asking Apple ID but pass code for updating the new soft ware not known.

    Hello Kewal,
    Thank you for the details of the issue you are experiencing when trying to perform an update.  I recommend trying to update using iTunes, and as always, it is a good idea to make a backup first. 
    iOS: Back up and restore your iOS device with iCloud or iTunes
    http://support.apple.com/kb/ht1766
    Update your iPhone, iPad, or iPod touch
    http://support.apple.com/kb/ht4623
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • Transaction code for checking the capacity of  a job

    Hi,
      Can anybody tell me if there is a transaction code for viewing the capacity of Job.
    Thanks and regards,
    Avinash.S

    Hi Avinash,
    I am not geeting what you want normally CM01 for w/c vise Load you can use.
    Pls elaborate yr problem a little bit.
    Umesh

  • How can we write the code for opening the command prompt and closing the

    how can we write the code in java for opening the command prompt and closing the cmd prompt from eclipse (cmd prompt should close when click on the turminate button in eclipse)

    rakeshsikha wrote:
    how can we write the code for opening the command prompt and closing theBy typing in Eclipse (which you seemingly have)?

  • T-Code for changing the default Exchange Rate reference for creating PO?

    Dear All,
           Can somebody kindly give me the T-Code for changing the default
    Exchange Rate reference for creating PO? Is there a Step by Step
    procedure before changing the default exchange rate?
    Thank you in advance.
    Regards,
    Gopesh

    Hi
    There is not such Tcode to change the default exchange rate from the PO.
    If you want you can confugure the exchange rate in the following path in the IMG,
    SPRO>MM>LIV>Incoming Invoice>Configure How Exchange Rate Differences Are Treated
    Hope it helps you.
    Cheers
    Umakanth

  • T.Code for checking the total value of a material

    Hi Experts,
      Can anybody tel me the T.code for checking the total value of a material which is procured in a specified period?
    Thanks in advance
    Channa

    Refer Tcode ME80FN click on Change Veiw & select Purchase Order History with this you can get PO-GRN-INVOICE Qty & Value details
    Last button on Application tool Bar it is in line of filter, total etc icons
    Also check below reports :
    MC$G - PURCHIS: Material PurchVal Selection
    MC$0 - PURCHIS: PurchGrp PurchVal Selection
    MC$< - PURCHIS: MatGrp PurchVal Selection
    MC$4 - PURCHIS: Vendor PurchVal Selection

  • What is the T-code for Viewing the Payment Advices....

    Hi,
    What is the T-code for Viewing the Payment Advices....
    Regards
    Sap Guru

    Hi,
    Payment advice creation - FBE1
    Payment advice Change - FBE2
    Payment advice Display - FBE3
    Payment advice Delete - FBE6.
    Assign points if helpful.
    Thanks,
    Vasu..

Maybe you are looking for

  • ITunes wont find my music on my external drive (when it used to!)

    I recently filled my PC's interntal harddrive with music to the point where it was so slow I had to to buy an external drive to keep it on. I tranferred all my music on to the hard drive and have had no problems with it until today. Today, I started

  • Error Code - 36 on OS x 10.5.8

    I am no longer able to connect to a networked PC from my mac. I still am able to connect to the Mac and transfer to the Mac from the PC. After coming across a post that referred to keyboard command Apple K I received the following error message... Th

  • Printing of Condition value at both header and Item level

    Dear Sap Gurus, Please any body tell me how to print the condition value at both header and at item level in PO print out. ie.  I am using RA00 at both item and header level and i want to print this value at both header and item level. Thanks and Reg

  • Unable to open FR studio in windows 7

    Hi All, I get the below error when I open the FR studio client in a Windows 7 system, "ActiveX component cant create object" I tried to uninstall-re install, however getting the below error when I tried to uninstall " JRE or JDK not found.Exiting" Ha

  • Selecting an area on a page

    The specifically defined "graphic select tool" of the older Acrobat versions does not exist in the later versions. How can I select an area on a page for copying or printing even if it is not an image? In some imported files the ordinary select tool