WebJul 12, 2024 · Video. Given a natural number ‘n’, print squares of first n natural numbers without using *, / and -. Examples : Input: n = 5 Output: 0 1 4 9 16 Input: n = 6 Output: 0 1 4 9 16 25. We strongly recommend to minimize the browser and try this yourself first. Method 1: The idea is to calculate next square using previous square value. WebJul 30, 2024 · In each step we are calculating cube of the term and then add it to the sum. This program takes O (n) time to complete. But if we want to solve this in O (1) or constant time, we can use this series formula − Algorithm cubeNNatural (n) begin sum := 0 for i in range 1 to n, do sum := sum + i^3 done return sum end Example Live Demo
Python program to find sum of n numbers with examples
WebJun 22, 2024 · A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and … WebMar 14, 2024 · A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. reading comprehension worksheets ielts
C Program for cube sum of first n natural numbers
WebFind the sum of first N natural numbers with Python Program. In this tutorial, we will find the sum of first N natural numbers. We shall explain the problem statement, and … WebFeb 16, 2024 · A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. WebApr 5, 2024 · We can easily see that the formula is true for n = 1 and n = 2 as sums are 1 and 5 respectively. Let it be true for n = k-1. So sum of k-1 numbers is (k - 1) * k * (2 * k - 1)) / 6 In the following steps, we show that it is true for k assuming that it is true for k-1. how to strip paint from wood cabinets