PROGRAM OF SUM OF N NUMBERS

/*PROGRAM TO CALCULATE SUM OF N NUMBERS. IF NO. IS NEGATIVE IT SHOULD BE IGNORED AND IF ZERO THEN PROCESS SHOULD BE TERMINATED*/

#include<conio.h>

#include<iostream.h>

class sum_of_nos

{

int i,n,sum;

public:

void process();

};

void sum_of_nos::process()

{

sum=0;

i=1;

while(i==1)

{

cout<<“Enter a positive number: “;

cin>>n;

if(n>0)

sum=sum+n;

else if(n<0)

cout<<“Ignoring negative number”<<endl;

else

i=0;

}

cout<<“Sum of given positive no.s is: “<<sum;

}

void main()

{

sum_of_nos s1;

clrscr();

s1.process();

getch();

}

Leave a Reply

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