Advertisement
Guest User

ex12-14 finis

a guest
Sep 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.32 KB | None | 0 0
  1. # Exercice 12
  2. n=100
  3. x=1
  4. for (i in 1:n)
  5. {
  6.   x=x+i
  7. }
  8. print(x)#5051
  9. # Exercice 13
  10. n=1
  11. x=0
  12. while (n<100)
  13. {
  14.   x = x + n
  15.   n = n + 1
  16. }
  17. print(x)
  18. print(sum(1:100))
  19. # Exercice 14
  20. # Conjecture de Syracuse
  21. x=41
  22. while(x>1)
  23. {
  24.   if (x%%2 == 0)
  25.   {
  26.     x = x / 2
  27.   }
  28.   else
  29.   {
  30.     x = 3 * x + 1
  31.   }
  32.   print(x)
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement