Answers for "sum of n natural numbers from end"

2

program to find sum till n natural numbers in python

#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)
Posted by: Guest on December-11-2021
1

sum of n natural numbers

//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;
}
Posted by: Guest on April-21-2022

Code answers related to "sum of n natural numbers from end"

Python Answers by Framework

Browse Popular Code Answers by Language