These were some examples my programming teacher used when teaching loops in class. I think the problems themselves aren't hard, but they're great for practicing loops and training your reaction speed. Also, my VB skills have gotten a lot rusty... So I'm attaching the C++ code for everyone to look at. Go study it yourselves~

The problem is the one in the image at the top: use only loops to produce the four triangles shown above. The solution is below.

Code:

Download: Box.net|4Shared|Dropbox|Google

#include #include <math.h>

using namespace std;

int main() { int x=5; cout«“三角形一:"«endl; for(int i=1;i<=x;i++){ for(int y=1;y<=i;y++){ cout«”"; } cout«endl; } cout«endl; cout«“三角形二:"«endl; for(int i=x;i>=1;i–){ for(int y=1;y<=i;y++){ cout«”"; } cout«endl; } cout«endl; cout«“三角形三:"«endl; for(int i=1;i<=x;i++){ for(int y=x;y>i;y–){ cout«” “; } for(int y=1;y<=i;y++){ cout«”*"; }

    cout<<endl;
}
cout<<endl;
cout<<"三角形四:"<<endl;
for(int i=1;i<=x;i++){
    for(int y=1;y<i;y++){
        cout<<" ";
    }
    for(int y=x;y>=i;y--){
        cout<<"*";
    }

    cout<<endl;
}
return 0;

}