Skip to content

Programming by Design

If you're not prepared to be wrong, you'll never come up with anything original. – Sir Ken Robinson

  • About
  • Java-PbD
  • C-PbD
  • ASM-PbD
  • Algorithms
  • Other

TEST JDoodle

Posted on July 22, 2024January 2, 2025 By William Jojo
Uncategorized

(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;
}


Post navigation

❮ Previous Post: TEST 6502
Next Post: Chapter 6502-4 – The Basics ❯

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Copyright © 2018 – 2025 Programming by Design.