0% found this document useful (0 votes)
2 views5 pages

C Pattern Programs

Uploaded by

shahzeb farooqi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

C Pattern Programs

Uploaded by

shahzeb farooqi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Square Pattern

#include <iostream>
using namespace std;

int main (){

for (int i=0; i<4 ; i++){

cout<<"* * * * *"<<endl;

}
return 0;
}
Christmas Tree Pattern

#include <iostream>
using namespace std;

int main() {
int n = 5;

for (int i = 1; i <= n; i++) {

for (int j = 0; j < n - i; j++) {


cout << " ";
}

for (int k = 0; k < 2 * i - 1; k++) {


cout << "* ";
}
cout << endl;
}

for (int i = 0; i < 3; i++) {


for (int j = 0; j < n - 2; j++) {
cout << " ";
}
cout << "* * *" << endl;
}

return 0;
}
Diamond Pattern

#include <iostream>
using namespace std;

int main (){


int n=5;

for (int i = 1; i <= n; i++) {


for (int j = 0; j < n - i; j++) {
cout << " ";
}
for (int k = 0; k < 2 * i - 1; k++) {
cout << " * ";
}
cout << endl;
}

for (int i = n - 1; i >= 1; i--) {


for (int j = 0; j < n - i; j++) {
cout << " ";
}
for (int k = 0; k < 2 * i - 1; k++) {
cout << " * ";
}
cout << endl;
}

return 0;
}
Pyramid Pattern

#include <iostream>
using namespace std;

int main (){


int n=5;

for (int i = 1; i <= n; i++) {

for (int j = 0; j < n - i; j++) {


cout << " ";
}

for (int k = 0; k < i*2 - 1 ; k++) {


cout << "*";
}
cout << endl;
}
return 0;
}

You might also like