---
title: "Write a program to find out the sum of 1 to n number which take minimum time to solve it."  
description: "Write a program to find out the sum of 1 to n number which take minimum time to solve it."  
author: "Ravi Vishwakarma"  
published: 2023-01-27  
updated: 2023-01-27  
canonical: https://www.mindstick.com/forum/157352/write-a-program-to-find-out-the-sum-of-1-to-n-number-which-take-minimum-time-to-solve-it  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Write a program to find out the sum of 1 to n number which take minimum time to solve it.

I am write [procedure](https://www.mindstick.com/forum/32/stored-procedure-return-datatype) for write [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) [sum](https://www.mindstick.com/forum/159332/how-can-i-use-sum-in-linq) of 1 to n numbers.\
but It take more [second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society) to solve it.\
like `var a = 1` , `var n = 12345678965487512` ,

`var sum = 12345678965487513` ,

## Replies

### Reply by Sanjay Goenka

I am writing a program in `JavaScript` language.

```javascript
function sum_of_numbers(n){
   return n * (n + 1) / 2;
}

console.log(sum_of_numbers(100));
```

## Output:

## 5050

### Reply by Amrita Bhattacharjee

The program to find out sum of 1 to n number in python will be the following:

```python
def sum_of_numbers(n):
   return n * (n + 1) // 2
print(sum_of_numbers(100))
```

### Reply by Rahul Roi

```c
#include <stdio.h>
int main(void) {
   int N, sum = 0, i = 1;
   scanf('%d', &N);
   sum = N*(N+1)/2;
   printf('Sum of first %d natural numbers is: %d', N, sum);
   return 0;
}
```

Output →

**Input : 5**\
**Output : Sum of first 5 natural numbers is: 15**\

This program take **O(1) time.**


---

Original Source: https://www.mindstick.com/forum/157352/write-a-program-to-find-out-the-sum-of-1-to-n-number-which-take-minimum-time-to-solve-it

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
