Computer Science, asked by Midhunbhaskar, 1 year ago

c++ program to find the first n natural numbers​

Answers

Answered by brainly7944
1

\huge{\blue{\textbf{\underline{C++ Program:-}}}}

#include <iostream>

using namespace std;

int main() {

long sum2=0;

int num;

cout << "Enter number: ";

cin >> num;

cout << num << endl;

for (int i=1; i<num; ++i) {

int sum=0;

for (int j=i+1; j<=num; ++j)

sum += j;

sum2 += i*sum;

}

cout << sum2 << endl;

return 0;

}

Attachments:
Answered by sushiladevi4418
0

Answer:

C++ program to find the first n natural numbers​.

Explanation:

#include<iostream>

using namespace std;

int main()

{

int i,n,sum=0;

cout<<"How many numbers? ";

cin>>n;

for(i=1;i<=n;++i)

{

sum+=i;

}

Similar questions