Sum = 1275. This sum of n numbers in c program allows the user to enter any integer value. In this tutorial we'll find sum of 'n' Natural numbers by creating user defined function in JavaScript. Input: A number n obtained using prompt Output: A table of numbers from 1 to n and their squares The script should be in the HTML form itself as script. when we converge towards zero we have finished our program so we need to exit and a non base case i.e. Following program shows you how to print sum of n natural numbers. Java Program to find Sum of N Natural Numbers using For loop. ; sum variable is used to hold the sum of all odd numbers. To run this applet, you first enter the number n you wish to have illustrated; space limitations require 0