xxxxxxxxxx
#sum of natural number till n.
n=int(input('no. :'))
gross=0
no=0
while no < n:
no+=1
gross+=no
print('no.', no ,'sum of n', gross)
print('no.',n,'total',gross)
xxxxxxxxxx
#1 + 2 + 3 + 4 + ........... + n = ?
l = int(input("Enter the range = "))
sum = 0
for x in range(1, l+1):
sum += x
if x != l:
print(x, "+ ", end='')
else:
print(x, end='')
print(" =", sum)
xxxxxxxxxx
//Created by https://ashif.in
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n; //Take Input
int sum = n*(n+1)/2; //Calculate Sum
cout<<sum; //Print Sum
return 0;
}
xxxxxxxxxx
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
int sum=0;
cin>>n;
for(int i=1;i<=n;i++)
{
sum+=i;
}
cout<<sum<<" ";
cout<<endl;
return 0;
}