A corrected version of the program is here.
Fixed programing errors are shown
in red,
with /*blue comments about changes made */.
Style enhancements (corrections or comments)
are green.
/* Project, Author, Date */
/* Size Of Factorial program */
/* (This is obviously not a first C program) */
#include <stdio.h>/* s removed, ; removed */
#include <math.h> /* need for log10 */
int main()
{
int len; /* size of n!, to be found */
int n; /* given value */
int j; /* iteration index. Identifier `i' was not the one used in the loop. */
double logNFac; /* accumulator for log10 (j!), j=0,...,n. Note: log10 (0!)=0.*/
/*Bring the declaration here. Declarations must precede executable statements*/
printf("Given an n>=0, this program computes the size of n!\n");
printf("Please enter n="); /* A prompt is needed before scanf */
scanf("%d", &n);
if (n<0) /* n==0 is still OK */
{ /*braces made properly indented */
printf("n<0, factorial undefined\n");
return (0); placed in its own line
}
/*'else' removed, since previous 'if' ends with 'return(0)'*/
/* In loop: log10 (n!) = sum log10(j), j=1,..,n. */
logNFac=0.0; /* Initialization */
for (j=1; j<=n; j++) /* no ; here */;
{ /* indent next line properly */
logNFac+=log10((double)j); /* using function log10 from "math.h" */
} /* no ; here */
/* Now that log10(n!) is computed, find its integral part */
len=(int) logNFac; /* cast to int */
/* if the value was rounded up, subtract one */
if (len > logNFac) /* remove 'then' */
--len;
/* To obtain size of n!, add 1 to the computed integral part */
len+=1; /* undefined varname `size' and invalid shorthand `=+' were here */
/* Print result, like this: Size of 4 ! is 2 */
printf("Size of %d ! is %d\n", n, len);
return(0);
}
(Here is a working code.)