+ 2

What's wrong with this code??? Expected output is same but still it is not correct.

#include <iostream> using namespace std; int main() { int n; cin >> n; for(int i =n ; i>=1 ; i--) { cout<<i; if(i==1) { break; } cout<< "\n"; if(i%5==0) { cout << "Beep \n"; } } return 0; }

29th Jun 2021, 2:09 PM
Anjali Sharma
Anjali Sharma - avatar
3 Respostas
+ 4
cout << "Beep\n";
29th Jun 2021, 2:26 PM
JaScript
JaScript - avatar
+ 5
Don't print a space after the Beep and everything should be fine.
29th Jun 2021, 2:21 PM
Shadow
Shadow - avatar
+ 1
Yeah there is extra space when u printing beep between beep and \n . That's why it failed in test case actually in such type of problems you have to take care of input amd outputs formats . And avoid your code for writing unnecessary lines .
29th Jun 2021, 6:19 PM
A S Raghuvanshi
A S Raghuvanshi - avatar