Untitled

mail@pastecode.io avatar
unknown
c_cpp
8 months ago
247 B
0
Indexable
Never
#include <iostream>
using namespace std;
int main()
{
    int n;
    int b=0;
    int i;
    cin >> n;
    if (n>0 && n!=0)
    {
       for (i =1; i<=n; i++)
           b +=i;
    }
else 
    {
    for (i=1; i>=n; i--)
    b+=i
    }
cout << b;
}