From babff04cc183e00fbb3bafc986b5b6bb6488249a Mon Sep 17 00:00:00 2001 From: trilok-77 <165671115+trilok-77@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:37:40 +0530 Subject: [PATCH] Create sum.cpp --- sum.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sum.cpp diff --git a/sum.cpp b/sum.cpp new file mode 100644 index 00000000000..3642f0e6659 --- /dev/null +++ b/sum.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + +int main() { + int n, sum = 0; + + cout << "Enter a positive integer: "; + cin >> n; + + for (int i = 1; i <= n; ++i) { + sum += i; + } + + cout << "Sum = " << sum; + return 0; +}