Write a function that take a number and return the previous and next numbers of the
first parameter passed. (Write codes for the main function also.)
#include <iostream>
using namespace std;
pair<int,int> PrevAndNext(int n)
{
pair<int, int> pr;
pr.first = n - 1;
pr.second = n + 1;
return pr;
}
int main()
{
int number;
cout << "Please, enter a number: ";
cin >> number;
pair<int, int> p=PrevAndNext(number);
cout << "Previous number is " << p.first<< endl;
cout << "Next number is " << p.second;
}
Comments
Leave a comment