ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1068. Сумма

where is wrong !! already it is working in codeblocks
Послано EIASER ARAFAT 6 ноя 2017 16:02
#include<stdio.h>

int main(){
int n,sum=0,i;
scanf("%d",&n);-

if(n>0){
  sum=(n*(n+1))/2;
}
else if(n<0){
        sum=(n*(-1*n+1))/2;
}
printf("%d",sum);


}
Re: where is wrong !! already it is working in codeblocks
Послано Mahilewets Nikita 6 ноя 2017 19:46
Maybe for N < 0 the formula is
SUM = ((2-N)*(N+1))/2

Edited by author 06.11.2017 19:47
Re: where is wrong !! already it is working in codeblocks
Послано Mahilewets Nikita 6 ноя 2017 19:55
The first term is N
The last term is 1
So the average is (1+N)/2

There are (-N) terms below zero
And there are two more terms
They are 0 and one
So there are (2-N) total terms

So the sum is average by total number of terms
Re: where is wrong !! already it is working in codeblocks
Послано ToadMonster 7 ноя 2017 01:19
Case "N == 0" isn't processed
Re: where is wrong !! already it is working in codeblocks
Послано jim 22 фев 2018 07:10
thank you for your hint!
Re: where is wrong !! already it is working in codeblocks
Послано WeXoB 20 май 2020 08:51

Edited by author 20.05.2020 08:52

Edited by author 20.05.2020 08:52
Re: where is wrong !! already it is working in codeblocks
Послано Juhi 15 июн 2020 11:20
But that should not make a difference