write a C++ program to print a triangle of prime numbers upto given number of lines of the triangle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include<iostream> #include<conio.h> using namespace std; int main() { int x1; int x2; int x3; int Number=3; int Banner=0; cout<<"Please enter the no of lines "; cin>> x1; int d= x1; for(x2=1;x2<= x1; x2++) { for(int e=1;e<=d;e++) { cout<<" "; } if(x2==1) { cout<<"2\n"; } else { for(x3=0; x3!= x2;) { Banner=0; for ( int k=2;k<Number;k++) { if((Number%k)==0) Banner=1; } if(Banner==0) { x3++; cout<<Number<<" "; } Number++; } cout<<"\n"; } d--; } getch(); return 0; } |
Output