1# Sum of natural numbers up to num
2
3num = 16
4
5if num < 0:
6 print("Enter a positive number")
7else:
8 sum = 0
9 # use while loop to iterate until zero
10 while(num > 0):
11 sum += num
12 num -= 1
13 print("The sum is", sum)
14
1#include<bits/stdc++.h>
2using namespace std;
3int main()
4{
5 int n;
6 int sum=0;
7 cin>>n;
8 for(int i=1;i<=n;i++)
9 {
10 sum+=i;
11 }
12 cout<<sum<<" ";
13 cout<<endl;
14 return 0;
15}