Sunday, February 1, 2015

Solution of 1068. Sum ( Timus Online Judge )

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

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

3 comments:

Compare equality of two string in C

#include <stdio.h> #include<string.h> int main() {     char* country = "Bangladesh";     char* country2;     ...