IN C++ VERY EASY
What's wrong with this code?
The following function prints a reverse half-pyramid populated by the alternating dots and stars (see example below). The odd rows contain stars and even rows contain dots. Debug the code to fix all the compilation and run-time errors, so that the code generates the desired output. For instance, when the 'n' value passed to the function is 6, the output would look like the following.
****** ..... **** ... ** .
void dotsAndStars(int n) { for (int i =1 ; i <n; i++) { for(int j=n, j>=i, j--) { if(i%2==0); { cout<<"*"; } else { cout<<"." } } } }
#include <iostream> using namespace std; void dotsAndStars(int n){ for(int i = 1;i<=n;i++){ for(int j = n;j>=i;j--){ if(i%2==0){ cout<<"."; } else{ cout<<"*"; } } cout<<endl; } } int main() { dotsAndStars(6); return 0; }
Get Answers For Free
Most questions answered within 1 hours.