0

Help

Напишите программу которая выводит сумму последовательности чисел 1 - 2 + 3 - 4 + 5 - 6 + 7 - ... и так далее до введенного числа n включительно. Входные данных Вводится одно натуральное число n - количество чисел. Выходные данные Выводится одно число - сумма чисел. Примечание Можно решить это задачу с использованием условного оператор, а можно и без него. Sample Input 1: 5 Sample Output 1: 3 Sample Input 2: 100 Sample Output 2: -50 https://code.sololearn.com/cGAcQB3s1uuy/?ref=app

10th Oct 2022, 6:48 AM
Plutos
Plutos - avatar
1 Answer
+ 1
A tip: in the programming world you are going to work with a lot of people all over the world and to communicate with each other we use english. If you don't know english I think it will be really important to learn it, also, you will get answers more quickly since more people can understand your question. Unfortunately I can't understand your question but you can solve this problem with a factor that has value either 1 or -1 and multiply by the number since you do minus plus minus plus minus ... (1-2+3-4+5-6...). If you instead start with 0+1-2+3... In every number you can multiply the factor by -1 (1*(-1) = -1 and (-1)*(-1)=1) and add to the sum the number*factor. I called.it signal on my code: https://code.sololearn.com/cDr5BRJFhra7/?ref=app I don't know if I could answer your question but Keep the good coding :)
10th Oct 2022, 7:39 AM
Tomás Ribeiro
Tomás Ribeiro - avatar