Thursday, 20 July 2017

wap of class to calculate sum

#include<iostream.h>
#include<conio.h>
class sum
{   public:
int a;
      sum(int b)
      {
      a=b;
      }
void s()
{
  int add=0;
  for(int i=1;i<=a;i++)
  {
add=add+i;
  }
  cout<<add;
}
};
void main()
{
clrscr();
int a;
cout<<"enter the no of terms\n";
cin>>a;
sum aj(a);
aj.s();
getch();
}

No comments:

Post a Comment