Write a code (or pseudo-code) for summing the first N odd numbers.
#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;
}
Comments
Leave a comment