Skip to content

Instantly share code, notes, and snippets.

@SirmaXX
Last active June 26, 2022 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SirmaXX/7f054b0fdcaf882ea781d35492eb7471 to your computer and use it in GitHub Desktop.
Save SirmaXX/7f054b0fdcaf882ea781d35492eb7471 to your computer and use it in GitHub Desktop.
mae for while
startTime <- Sys.time()
y<-c(10,8,6,4,2)
x<-c(5,4,3,2,1)
n<-length(y)
toplam=0
i <- 1
while (i <= n) {
diff=y[i]-x[i]
toplam=toplam+diff
i <- i + 1
}
sonuc=toplam/n
print(sonuc)
endTime <- Sys.time()
print(endTime-startTime )
#Output
#startTime <- Sys.time()
#
# y<-c(10,8,6,4,2)
# x<-c(5,4,3,2,1)
# n<-length(y)
#
# toplam=0
#
# i <- 1
# while (i <= n) {
# diff=y[i]-x[i]
# toplam=toplam+diff
# i <- i + 1
#
# }
#
#
# sonuc=toplam/n
# print(sonuc)
#[1] 3
#
# endTime <- Sys.time()
#
# print(endTime-startTime )
#Time difference of 0.009809256 secs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment