Answer to Question #298935 in C++ for Okuhle

Question #298935

Write a code (or pseudo-code) for summing the first N odd numbers.

1
Expert's answer
2022-02-17T07:40:56-0500
#include <iostream>
#include <string>


using namespace std;


int main() {
	
	int N;
	int sum=0;
	cout<<"Ente n: ";
	cin>>N;
	for(int i=0;i<N;i++){
		if(i%2==1){
			sum+=i;
		}
	}
	cout<<"Sum the first N odd numbers: "<<sum<<"\n\n";


	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog