Answer to Question #307232 in C++ for ritesh

Question #307232

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.)




1
Expert's answer
2022-03-07T10:27:10-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog