Advertisement
Mouamle

Arithmetic progression

Feb 17th, 2016
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.47 KB | None | 0 0
  1. function solve(a, n, d)
  2.   t = {}
  3.   for i = a, n*d, d  do
  4.     table.insert(t, i)
  5.   end
  6.   tempstr = ""
  7.   for k, v in pairs(t) do
  8.     tempstr = tempstr .. "| " .. v .. " | "
  9.   end
  10.   Un = " { " .. tostring(a + (n-1)*d) .. " } "
  11.   return tempstr .. "\n" .. "The value when n = { " .. n .. " } is:" .. Un;
  12. end
  13.  
  14. -- example :
  15. --[[
  16. print(solve(7, 6, -3))
  17.     output{
  18.         | 7 | | 4 | | 1 | | -2 | | -5 | | -8 | | -11 | | -14 | | -17 |
  19.         The value when n = { 6 } is: { -8 }
  20.     }
  21. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement