Friday, September 20, 2019

C++ Language Program for Addition of n Numbers.

BACHELOR OF COMPUTER APPLICATION (B.C.A.) FIRST SEMESTER
Here you will get simple C++ program 

C++ Language Program for Addition of n Numbers.


IT IS THE SMALLEST LOGIC USED FOR CODING OF THIS PROGRAM.

IN WHICH YOU CAN CREATE OWN VARIABLES AND FUNCTIONS.

User will input n Numbers and that Numbers is Added by Logic, Then it Addition will be display on screen.

The program coding is given below.

#include <iostream.h>
#include <conio.h>
class ADD
{
int n, sum;
public:
void getdata()
{
cout << "Enter a positive integer: ";
    cin >> n;
}
void display()
{
sum=0;
for (int i = 1; i <= n; ++i)
{
        sum += i;
    }
    cout << "Sum = " << sum;
}
};
void main()
{
clrscr();
ADD a1;
a1.getdata();
a1.display();
getch();
}

Output will be given after you compile it.

No comments:

Post a Comment