Adding numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Adding numbers

Question: instead of adding each number Manuel like this: 1 2 3 4 5 6 7 8 9. Is it possible to make a code that keeps adding 1 to the number and how?

30th Oct 2018, 8:34 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar
18 Answers
+ 3
I saw this on discord lol. Okay, so what you need to do is provide me with sample input and sample output.
30th Oct 2018, 9:08 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
So your input is: "1 2 3 4 5 ... 98 99 100" And your output is: "5050"
30th Oct 2018, 9:19 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
So basically, what do you want to enter as input and what do you want to get as a result?
30th Oct 2018, 9:13 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
Sure, just use a loop. <?php for($i=1;$i<=10;$i++){ //increase number by one until 10 echo $i; //print number echo " "; //print space } ?> output: 1 2 3 4 5 6 7 8 9 10
30th Oct 2018, 9:35 AM
Matthias
Matthias - avatar
+ 1
A simple For loop that keeps incrementing by 1 should do. In Lua the code would be the following: for i = 1, 100 do print(i) end
30th Oct 2018, 9:59 AM
Aatif Zaidi
Aatif Zaidi - avatar
+ 1
You can embed php in html. Or you can do it with Javascript. Please have a look at the teaching section there the basics of these languages is explained
30th Oct 2018, 10:05 AM
Matthias
Matthias - avatar
+ 1
This would be the code if you want it in HTML. Write the following in Javascript: document.write("<p style='font-weight:bold'>"); for(i=1;i<=100;i++) { document.write(i); document.write("<br/>") } document.write("</p>");
30th Oct 2018, 10:07 AM
Aatif Zaidi
Aatif Zaidi - avatar
+ 1
let me try
30th Oct 2018, 10:08 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar
+ 1
what im really trying to is make a select property with numbers from 1900 up to 2018 to a registration for age. just gonna learn it from sololearn them self. thanks for helping👍💪
30th Oct 2018, 10:19 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar
0
just wanted to get a fast answer lol 😂🤣. aaaaaand. i have no idea what you are taking about
30th Oct 2018, 9:10 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar
0
like 1 and 10?
30th Oct 2018, 9:11 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar
0
just want to have the first number to be one and the last number to be 100 without whriting it manuel
30th Oct 2018, 9:14 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar
0
like 1 2 3 4 5 up to 100
30th Oct 2018, 9:14 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar
0
sorry man i dont think you understand. instead of whriting <p> 1 2 3 4 5.... 100 </p> can you just whrite a code that does that for you?
30th Oct 2018, 9:21 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar
0
thanks
30th Oct 2018, 9:37 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar
0
is it possible to do in Html, css or javascript?
30th Oct 2018, 9:39 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar
0
can i use this in html, css or javascript
30th Oct 2018, 10:00 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar
0
matthias okay thanks for the help. im quick trying Aatif’s solution if it works it works. if it do not work somethings wrong with me and im just gonna wait until sololearn learns me how to do 😂🤣
30th Oct 2018, 10:11 AM
Alexander R. Storr-Hansen
Alexander R. Storr-Hansen - avatar