(Updated November 23, 2024)
FactorialIter.java
public class FactorialIter {
public static int fact(int n) {
int prod = 1;
if ( n < 0 )
throw new IllegalArgumentException("Value cannot be negative.");
for (int i = n; i > 1; i--)
prod = prod * i;
return prod;
}
public static void main(String [] args) {
System.out.println(fact(0));
System.out.println(fact(4));
System.out.println(fact(15));
}
}
output.c
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
char c;
char name[30];
snprintf(name, sizeof name, "%s", "John Smith");
c = 'L';
fputc(c, stdout);
fputc('\n', stdout);
puts(name);
printf("%s", name);
fputs(name, stdout);
return 0;
}