Write a sample C program with errors for debugging purpose
To learn C program debugging, let us create the following C program that calculates and prints the factorial of a number. However, this C program contains some errors in it for our debugging purpose.
$ vim factorial.c # include <stdio.h> int main() { int i, num, j; printf ("Enter the number: "); scanf ("%d", &num ); for (i=1; i<num; i++) j=j*i; printf("The factorial of %d is %d\n",num,j); }
$ cc factorial.c $ ./a.out Enter the number: 3 The factorial of 3 is 12548672