C++ 学习笔记_0007_循环(星号图 改正版)

来源:互联网 发布:java jar 选择 jdk 编辑:程序博客网 时间:2024/05/20 20:13

发现先前对程序的运行输出理解有误,重做一遍  之前的练习

//图案a#include<iostream>using namespace std;int main(){int n = 6, i;for (i = 1; i <= n; i++){for (int j = 2*n - 1; j >= 2*i - 1; j--)cout << "*";cout << endl;}return 0;}/* 其他方法 for(i = n; i >= 1; i--){for (int j = 1; j <= 2*i - 1; j++)cout << "*";}*/

//图案b#include<iostream>using namespace std;int main(){int n = 6, i;for (i = 1; i <= n; i++){for (int j = n; j > i; j--)cout << "_";for (int j = 1; j <= i; k++)cout << "*";cout << endl;}return 0;}/* 其他方法for (i = 1; i <= n; ++i)     {          for(j = 1; j <= n-i; ++j)              cout << " ";          for(j = 1; j <= i; ++j)              cout << "*";          cout<<endl;      } */


//图案c#include<iostream>using namespace std;int main(){int n = 6, i;for (i = 1; i <= n; i++){for (int j = 1; j < i; j++)cout << " ";for (int j = 2*n - 1; j >= 2*i - 1; j--)cout << "*";cout << endl;}return 0;}/* 其他方法for(i = n; i >= 1; --i)    {          for(j = 1; j <= n-i; ++j)             cout << " ";          for(j = 1; j <= 2*i-1; ++j)             cout << "*";          cout << endl;      }  */ 

//图案d#include<iostream>using namespace std;int main(){int n = 6, i;for (i = 1; i <= n; i++){for (int j = 1; j <= n - i; j++)cout << " ";for (int j = 1; j <= 2*i -1; j++)cout << "*";cout << endl;}return 0;}/* 其他方法for (i = n; i >= 1; i--){for (int j = 1; j <= i - 1 ; j++)cout << " ";for (int j = 2*n - 1; j >= 2*i - 1; j--)cout << "*";cout << endl;}*/


//图案e#include<iostream>using namespace std;int main(){int n = 6, i;for (int j = 1; j < n; j++)cout << " ";cout << "*" << endl;for (i = 1; i <= n - 2; i++){for (int j = 1; j < n - i; j++)cout << " ";cout << "*";for (int j = 1; j <= 2*i -1; j++)cout << " ";cout << "*" << endl;}for(int j = 1; j <= n*2 - 1; j++)cout << "*";cout << endl;return 0;}


//图案f#include<iostream>using namespace std;int main(){int n = 6, i;for (i= 1; i <= n; i++){for (int j = 1; j <= n - i; j++)cout << " ";for (int j = 1; j <= 2*i - 1; j++)cout << "*";cout << endl;}for (i = 1; i < n; i++){for (int j = 1; j <= i; j++)cout << " ";for (int j = 1; j <= 2*(n - i) - 1; j++)cout << "*";cout << endl;}return 0;}





0 0
原创粉丝点击