Print a pattern for given integer. First reduce 5 one by one until we reach a negative or 0. After we reach 0 or negative, we add 5 until we reach n. Input : 16 Output : 16 11 6 1 -4 1 6 11 16 || Input : 20 Output : 20 15 10 5 0 5 10 15 20
Thu Feb 06 2025 04:53:37 GMT+0000 (Coordinated Universal Time)
Saved by
@Rohan@99
#include <iostream>
using namespace std;
int initialValue;
void IncreaseNumber(int n){
if(n == initialValue){
return;
}
n += 5;
cout << n << " ";
IncreaseNumber(n);
}
void DecreaseNumber(int n){
if(n <= 0){
cout << n << " ";
IncreaseNumber(n);
return;
}
cout << n << " ";
n -= 5;
DecreaseNumber(n);
}
int main() {
cin >> initialValue;
DecreaseNumber(initialValue);
return 0;
}
content_copyCOPY
Comments