Sum of Numbers

Sum of Numbers

Tags: Basics

Credit: CodingChallenge

Difficulty: Beginner

Type: Text

Category: Practice

Time Allowed: 5 s

Description:

Write a function that takes a positive integer N and returns the sum of all numbers from 1 to N using a while loop. This problem is designed to help you practice using while loops. The function should accept one parameter and return the sum.

Constraints:

  • The input will be a positive integer greater than zero.
  • The function should return an integer representing the sum.

Example:

  • Input: 5
  • Output: 15 // Explanation: 1 + 2 + 3 + 4 + 5 = 15

Test Case Input Expected Output
1 1 1
2 5 15
3 10 55
4 3 6

Please register or login to submit solutions to challenges.