PROGRAM TO PRINT SUM OF N NATURAL NUMBERS

/*PROGRAM TO PRINT SUM OF N NATURAL NUMBERS*/

#include<conio.h>

#include<iostream.h>

class natural

{

int i,sum,n;

public:

void process();

};

void natural::process()

{

cout<<“Enter any natural number: “;

cin>>n;

sum=0;

cout<<“Natural numbers upto “<<n<<” are: “;

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

{

cout<<i<<”  “;

sum=sum+i;

}

cout<<“\nSum of first “<<n<<” natural numbers is: “<<sum;

}

void main()

{

natural n1;

clrscr();

n1.process();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *