C++ Program to add two numbers using structure and function


In this program, You will learn how to add two numbers using structure and function in C++.


20 = 10 + 10

50 = 30 + 20


Example: How to add two numbers using structure and function in C++

Run it Now
#include<iostream>
using namespace std;

struct Test {
    int x, y, z;
};

void add(Test t) {
    t.z = t.x + t.y;
    cout << "\nThe Sum is :" << t.z;
}

int main() {

    struct Test t;

    cout << "Enter Two Numbers :";
    cin >> t.x >> t.y;

    add(t);

    return 0;
}

Output:

Enter Two Numbers :30 40
The Sum is :70