Question: Sum of series using c language

*sample* input : 12 15
*sample* output : 54

*sample* input : 1 100
*sample* output : 5050

```
#include <stdio.h>

int main(){

    int a, b;

    scanf("%d %d", &a, &b);
    printf("%lld",a*(b+1)/2);

    return 0;
}

```

Answer: 
Your formula: `a*(b+1)/2` is wrong

For `a + (a+1) + (a+2) + ... + (b-1) + b` use the formula:

```
((b+1)*b - a*(a-1))/2  or (b-a+1)(b+a)/2

```

(assuming that `b >= a`)

So the program could be:

```
#include <stdio.h>

int main(void)
{
    int a, b;

    if (scanf("%d %d", &a, &b) != 2) exit(1);
    if (b < a) exit(1);
    printf("%d", ((b+1)*b - a*(a-1))/2);

    return 0;
}

```
The `%lld` format specifier is used to print a `long long int`. The argument you're passing has type `int`. Mismatching format specifiers triggers [undefined behavior](https://en.wikipedia.org/wiki/Undefined_behavior), which in this case will likely result in output you don't expect.

To print an `int` use `%d`.

```
printf("%d",a*(b+1)/2);

```