Friday, June 4, 2021

program find the sum of natural odd numbers (POP) (128)

#include<iostream>

using namespace std;

int main()

{

int i,n,sum=0;

cout<<"please enter a number:";

cin>>n;

cout<<"the odd number are:"<<endl;

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

{

cout<<i*2-1<<endl;

sum=sum+i*2-1;

}

cout<<"the sum of these natural odd numbers are: "<<sum<<endl;

} 

No comments:

Post a Comment