go to previous page   go to home page   go to next page

Answer:

Optimizing compilers sometimes examine the source code and rewrite it into something more efficient, such as:

 main()
 {
   print(  mysub( 6 ) );
 }

Example Program: Factorial( N )

The next example program prompts the user for an integer, reads in the integer, and prints the factorial. The SPIM console window shows the output of several runs of the program. The pseudo-code for the program is:


#  main()
#  {
#    int a, b;  // a: 0($fp),  b: 4($fp)
#    write("enter an int:")
#    read( a );
#    b = fact( a );
#    write("factorial is:")
#    print( b );
#  }

#  int fact( int n )
#  {
#    if ( n <= 1 )
#      return 1;
#    else
#      return n*fact(n-1);
#  }

 

QUESTION 17:

You have very likely seen the factorial function before (and are very likely sick of it!) But just in case:

What is the factorial of 5?