#include<bits/stdc++.h>
using namespace std;
/// Typedef
typedef long long int ll;
//Long Data type
#define scl1(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld %lld", &a, &b)
#define scl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define scl4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
int main(){
ll i,j,n,m,a=0,b=0,c=0,d=0,e=0,f=0,g=0,t,ln,ck=0,dk=0, loc2=0;
scl1(n);
if(n>0){
for(i=1; i<=n; i++){
ck+=i;
}
cout<<ck<<endl;
}
else{
for(i=1; i>=n; i--){
ck+=i;
}
cout<<ck<<endl;
}
}
Or
#include<bits/stdc++.h>
using namespace std;
/// Typedef
typedef long long int ll;
//Long Data type
#define scl1(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld %lld", &a, &b)
#define scl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define scl4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
int main(){
ll i,j,n,m,a,d,t,l,k,b,c,ck=0,dk=0, loc2=0;
scl1(n);
if(n>1)
m = n;
else
m = (n*-1)+2;
ck = m*(n+1);
cout<<ck/2<<endl;
}
0 Comments
If you have any doubts, Please let me know