0
What is the error in it??
include <iostream> using namespace std; int main() { int n; cin >> n; int i; for(i=0;n>=1;--n ) { if(n%5==0) { cout << "Beep"; continue; } else { cout << n; } } //your code goes here return 0; } Question is: 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
4 Antworten
+ 2
Shaik.Shahir
First print number then print Beep if number is divisible by 5 and also no need to use continue.
cout << n << endl;
if (n % 5 == 0)
cout << "Beep" << endl;
+ 2
Shaik.Shahir
Check your for loop also. It should be
for (i = n; i >= 1; i--)
-------
for (i = n; i >= 1; i--) {
cout << i << endl;
if (i % 5 == 0)
cout << "Beep" << endl;
}
+ 1
Why are you posting C++ code and the tag is pointed to Python?🤔
int n;
cin >> n;
for(; n>=1; --n) {
if(n%5==0) {
cout << "Beep\n";
} else {
cout << n << endl;
}
}
- 1
Hooo! I forgot