c++ program to find the first n natural numbers
Answers
Answered by
1
#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
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