Problem

Discussion in 'C' started by PEANUTS, Oct 25, 2006.

  1. PEANUTS

    PEANUTS New Member

    Joined:
    Oct 13, 2006
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    I have done a program, it works but i used a book to help me as i was seriously stuck and unsure what i have actually done in fields

    "register an integar" as i normally put int iCount (iCount my integar i nominate)

    "Long factorial"

    and "Return 0" as i use getch(); normally

    My code:
    Code:
    
    /* Name:
    
    Cameron Owen
    CIC Y1 G1
    Software Development
    Factors
    
    */
    
    #include<stdio.h>
    int main()
    {
    register int count;                         
    int iCount;				
    long factorial;
    printf("Compute the factorial of what number?");       	
    scanf("%d",&iCount);
    for (factorial =1L, count=1; count<=iCount; count++)
    	factorial *=count;
    printf("%d!=%d\n",iCount, factorial);                    
    return 0;														
    }
     
    Last edited by a moderator: Oct 26, 2006
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    So what you could not understand?
     
  3. PEANUTS

    PEANUTS New Member

    Joined:
    Oct 13, 2006
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    The lines that i wrote
    "register an integar"

    "Long factorial"

    "Return 0"

    I would usually make a comment after each for my understanding,

    eg.

    if i wrote

    getch(); // get a character from the keyboard


    something along those lines
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Code:
    register int count; // declare the first counter  
    int iCount;	// declare the second counter	
    long factorial; // Declare the var for output 
    printf("Compute the factorial of what number?");   // display message to user
    scanf("%d",&iCount); // Get the input from user
    // Loop through to multiply the numbers to calc fact
    for (factorial =1L, count=1; count<=iCount; count++)
    	factorial *=count;
    printf("%d!=%d\n",iCount, factorial);  // Print output
    
     
  5. PEANUTS

    PEANUTS New Member

    Joined:
    Oct 13, 2006
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Thank you so much, cleared it all up for me.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice