C++ introductory tutorial – -9 loop and conditional statements exercises and summary
You can test out how to output this yourself.
Think for yourself, don’t rush to see the answer. Prompts are made with double loops and if statements.
The answer is below, so don’t wait
#include <iostream>
using namespace std;
int main (a)
{
int i,j;
for(i=1; i<=5; i++) { // There are 5 rows in total
for(j=i; j>=1; j--)// The number of # output per line is the number of lines
{
cout<<"#";
}
cout<<endl;
}
return 0;
}
Copy the code
To summarize: the if statement and the for statement must be learned. Condition statement and circular statement carefully explore clear, baidu can assist. Learn these two, c++ basic will be more than half.
Because c++ has a procedural programming component, and it also has object orientation. So the conditional statements and the loop statements, they actually sort of clarify the logic.