# Luận văn quản trị Công trình định nghĩa về Công trình đầu cơ

For example I write a program like this;
I write a number like “4564983”
and my program run like “4.1+5.2+6.3+4.4+5.9+6.8+7.3=158”
How can ı write this program ?(Sorry for terrible english)

Sorry, dont’ understand your question. Can you explain as detailed as you can?

I don’t understand the connection between the number and the mathematical operation, you need to explain more

I’ll explain it in your native language

So this is my understanding of it, lets see if I can explain it.

`4564983`

`4.1 + 5.2 + 6.3 + 4.4 + 5.9 + 6.8 + 7.3`

So for the first 4 numbers (or half of the numbers) you are adding the numbers position to it as a decimal point.

`4.1 + 5.2 + 6.3 + 4.4`

1 number is 4 + `.1` === 4.1
2 number is 5 + `.2` === 5.2
3 number is 6 + `.3` === 6.3
4 number is 4 + `.4` === 4.4

The last 3 numbers it looks like you want to switch the decimal point and the number

`5.9 + 6.8 + 7.3`

5 number is 9 decimal number 5 === `5.9`
6 number is 8 decimal number 6 === `6.8`
7 number is 3 decimal number 7 === `7.3`

I might have explained that really poorly, also I might just be wrong.

``````function numbers(str){
const arr = str.split('');
let new_arr = [];
for (let i = 0; i < arr.length; i++){
if(i < 4){
new_arr.push(arr[i] + "." + (i + 1));
}else{
new_arr.push((i + 1) + "." + arr[i]);
}
}

return new_arr;
}

function sum(arr){
let suma = 0;
for (let i = 0; i < arr.length; i++){
suma += parseFloat(arr[i]);
}

return suma;
}
const new_array = numbers('4564983');
//function numbers return [ "4.1", "5.2", "6.3", "4.4", "5.9", "6.8", "7.3" ]

console.log(sum(new_array));
// function sum return 39.99999
``````
1 Like

That does not solve your problem but it is a similar function, I will write you a solution soon.

``````function addNumbers (num){
output = [];
var sNumber = num.toString();
var nLength = sNumber.length;
var sum2;

for (var i = 0, len = sNumber.length; i < len; i += 1) {
output.push(+sNumber.charAt(i));
}
for (var i = 0, sum = 0; i < output.length; sum += output[i++]);
sum2 = sum + ((nLength/2)*nLength)/10;

return sum2;

}