Program to show Next and Previous 5 Integers from Given One.
Problem:
Write a program that takes an integer number from user and shows the next 5 and then previous 5 numbers on the screen.
Solution:
# include <iostream> using namespace std; int main() { int num; int i=0; int temp; cout<<"Enter the number"<<endl; cin>>num; temp=num; cout<<endl; while(i<5){ cout<<++num<<endl; i++; } cout<<endl; i=0; while(i<5){ cout<<--temp<<endl; i++; } return 0; }
Write a program that takes an integer number from user and shows the next 5 and then previous 5 numbers on the screen.
Solution:
# include <iostream> using namespace std; int main() { int num; int i=0; int temp; cout<<"Enter the number"<<endl; cin>>num; temp=num; cout<<endl; while(i<5){ cout<<++num<<endl; i++; } cout<<endl; i=0; while(i<5){ cout<<--temp<<endl; i++; } return 0; }