برنامهای بنویسید که شکل زیر را چاپ کند.
1
1 2 1
1 2 3 2 1
…
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
روش اول (آسان)
/* print12321 v1 1 1 2 1 1 2 3 2 1 ... 12 Dec 2015 C++ Language By: Sina Moradi http://Samiantec.ir */ #include#include using namespace std; int main() { cout<<"Please enter count of rows: "; int n; cin>>n; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= i; ++j) cout << j << " " ; for (int k = i - 1; k > 0; --k) cout << k << " " ; cout << endl; } getch(); return 0; }
روش دوم
/* print12321 v2 1 1 2 1 1 2 3 2 1 ... 12 Dec 2015 C++ Language By: Sina Moradi http://Samiantec.ir */ #include#include using namespace std; int main() { cout<<"Please enter count of rows: "; int n; cin>>n; for(int i=1;i<=n;i++) { for(int j=1;j<2*i;j++) if(j<=i) cout<