#include<iostream> using namespace std; void line(int,int,int); int main() {int i; do {cout<<"How many rows? "; cin>>i; if(i<0) cout<<"must be nonnegative\n"; }while(i<0); line(i,1,i); system("pause"); return 0; } void line(int m,int n,int p) {int i; if(m>p) return; for(i=0;i<m;i++) cout<<"*"; if(m>0) cout<<endl; if(m==0||n==0) line(m+1,0,p); else line(m-1,n,p); } --------------------------------- #include<iostream> using namespace std; void line2(int,int,int); int main() {int i; do {cout<<"How many rows? "; cin>>i; if(i<0) cout<<"must be nonnegative\n"; }while(i<0); line2(1,1,i); system("pause"); return 0; } void line2(int m,int n,int p) {int i; if(m<n) return; for(i=0;i<m;i++) cout<<"*"; if(m>0) cout<<endl; if(m==p||n==0) line2(m-1,0,p); else line2(m+1,n,p); }
iostream
stdio.h
cin
cout
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)