Proof of Correctness: factorial.c

next

Step0: Initial code - how to prove correct from PRE- to POST-condition?

int factorial(int x) {
int f, y;
  // PRE-CONDITION: x >= 0              
 
  y = 1;
                    
  
  f = 1;
 
  
                                                  
  
  while (y <= x) {
    
                                                     
    
    f = f * y;
    
                                                    
    
    y = y + 1;
                                                     
  
  } // end while
 
                                                   
  
  // POST-CONDITION: f = x!        

  return f;
}