Welcome to Westonci.ca, your one-stop destination for finding answers to all your questions. Join our expert community now! Our Q&A platform offers a seamless experience for finding reliable answers from experts in various disciplines. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.
Sagot :
Answer:
#include <iostream>
using namespace std;
void swapInts(int* x, int* y) {
*x = *x + *y;
*y= *x - *y;
*x = *x - *y;
}
int main(){
int num1, num2;
cout << "Before swap:";
cin>>num1; cin>>num2;
swapInts(&num1, &num2);
cout<<"After swap:"<<num1<<" "<<num2;
}
Explanation:
The function begins here:
This line defines the function
void swapInts(int* x, int* y) {
The next three line swap the integer values
*x = *x + *y;
*y= *x - *y;
*x = *x - *y;
}
The main begins here:
int main(){
This line declares two integer variables
int num1, num2;
This line prompts the user for inputs before swap
cout << "Before swap:";
This line gets user inputs for both integers
cin>>num1; cin>>num2;
This line calls the function
swapInts(&num1, &num2);
This prints the numbers after swap
cout<<"After swap:"<<num1<<" "<<num2;
}
We hope our answers were useful. Return anytime for more information and answers to any other questions you have. Thank you for your visit. We're committed to providing you with the best information available. Return anytime for more. We're here to help at Westonci.ca. Keep visiting for the best answers to your questions.