Skip to content

Instantly share code, notes, and snippets.

@sixtyfive
Created October 13, 2016 12:19
Show Gist options
  • Save sixtyfive/d00cc1773a8c07b757ad8f7bdd6e99d1 to your computer and use it in GitHub Desktop.
Save sixtyfive/d00cc1773a8c07b757ad8f7bdd6e99d1 to your computer and use it in GitHub Desktop.
Jockers ch. 3, ex. 2
#!/usr/bin/env Rscript
#
# Obacht! Interaktiver Modus und Skripte funktionieren in R teils verschieden
# voneinander. Interaktiv scan() = geskriptet readLines()! Oder man löst es wie
# unten zu sehen...
cat("\nBitte geben Sie eine positive ganze Zahl ein: ")
benutzereingabe = scan(file('stdin'), what = integer(), n = 1)
gausssche_summe = sum(1:benutzereingabe) # Wenn man Vektoren benutzen möchte.
# Viel cooler ist Mathe:
# gausssche_summe = x * (x - 1) / 2
cat(paste('Die Gaußsche Summe von', benutzereingabe, 'ist', gausssche_summe, "\n\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment