0

can any one tell me the code of different types of pyramid...please

30th Sep 2016, 11:03 AM
Ananya Sinha
Ananya Sinha - avatar
3 Réponses
+ 1
http://www.programiz.com/cpp-programming/examples/pyramid-pattern For example, #include <iostream> using namespace std; int main() { int i,space,rows,k=0; cout << "Enter the number of rows: "; cin >> rows; for(i=1;i<=rows;++i) { for(space=1;space<=rows-i;++space) { cout << " "; } while(k!=2*i-1) { cout << "* "; ++k; } k=0; cout << endl; } return 0; } or #include <iostream> using namespace std; int main() { int i,j,rows; cout << "Enter the number of rows: "; cin >> rows; for(i=1;i<=rows;++i) { for(j=1;j<=i;++j) { cout << "* "; } cout << endl; } return 0; }
30th Sep 2016, 12:15 PM
Alexander Johnson
Alexander Johnson - avatar
0
#include<iostream> using namespace std; int main() { int i,n,j,l,k=1; cout<<"How many rows?"; cin>>n; i=n; while( i>=0 && K<=n+1) { l=1; j=1; while(j<=i) { cout<<" "; j++; } while(l<=K) { cout<<"* "; l++; } cout<<endl; I--; K++; } return 0; }
12th Dec 2016, 7:11 AM
Ganesh Kulkarni
Ganesh Kulkarni - avatar
0
it is very important to understand the logic behind it. it's that the first triangle pointing downwards should be of spaces . then a normal triangle of stars should be printed. but, if we take two different for loops for these two triangles,then,the second triangle will get printed after first. hence, it's more convenient to take while loop using && operator
12th Dec 2016, 7:17 AM
Ganesh Kulkarni
Ganesh Kulkarni - avatar