New course! Every coder should learn Generative AI!
Try a free lesson+ 1
c++
You need to make a countdown app. Given a number N as input, output numbers from N to 1 on separate lines. Also, when the current countdown number is a multiple of 5, the app should output "Beep". Sample Input: 12 Sample Output: 12 11 10 Beep 9 8 7 6 5 Beep 4 3 2 1
8 Answers
+ 3
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
while(n>=1){
if(n%5==0){
cout<<n<<endl;
cout <<"Beep" << endl;
}
else{
cout<<n<<endl;
}
n--;
}
return 0;
}
Don't code according to test case. 12 is just a sample test case. There could b any test case. And to check whether a number is a multiple of another number, take its modulus with the number you want to check. Is it equal to 0 or not.
+ 3
HK Lite
No need else part here, you can simply do:
cout << n << endl;
if (n % 5 == 0)
cout << "Beep" << endl;
+ 1
#include <iostream>
using namespace std;
int main() {
int r;
int n;
int number= 0;
cin >> n;
if
( r < 12) {
cout << r << endl;
r-=1;
r--;
}
number = 0/5;
if (number/5)
cout << "beep" << endl;
return 0;
}
+ 1
And this
+ 1
#include <iostream>
using namespace std;
int main() {
int n;
int number= 0;
cin >> n;
if ( number/5 )
cout << "beep" << endl;
while (number > 12) {
number-=12;
n--;
}
return 0;
}
+ 1
Is there a question in there somewhere?
https://www.sololearn.com/discuss/333866/?ref=app
https://www.sololearn.com/discuss/1316935/?ref=app
+ 1
HK Lite your code doesnt inculde 15 it replaces it with beep
Its suppose to go 15 beep 14..
+ 1
HK Lite yea true