PROGRAM TO SHOW THE CONCEPT OF STATIC DATA

/*PROGRAM TO SHOW THE CONCEPT OF STATIC DATA*/

#include<conio.h>

#include<iostream.h>

class stat_data

{

int i,sum;

static int counter;          //STATIC DATA DECLARATION

public:

void process();

};

void stat_data::process()

{

cout<<“Numbers upto “<<counter<<” are:\n”;

sum=0;

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

{

sum=sum+i;

cout<<i<<”  “;

}

cout<<“\nSum of numbers upto “<<counter<<” is: “<<sum;

}

int stat_data::counter=10;      //STATIC DATA DEFINITION

void main()

{

stat_data s1;

clrscr();

s1.process();

getch();

}

Leave a Reply

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