0% found this document useful (0 votes)
21 views4 pages

Apoorv Jain Coding Assingment 3

The document contains code snippets to print different types of pyramid patterns using for loops in C++. The first code snippet prints an asterisk pyramid where the number of asterisks increases with each row. The second code prints a number pyramid with increasing numbers from 1 to the number of rows. The third code is similar but prints the row number instead of the column number.

Uploaded by

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

Apoorv Jain Coding Assingment 3

The document contains code snippets to print different types of pyramid patterns using for loops in C++. The first code snippet prints an asterisk pyramid where the number of asterisks increases with each row. The second code prints a number pyramid with increasing numbers from 1 to the number of rows. The third code is similar but prints the row number instead of the column number.

Uploaded by

jainanuj7923
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Q1:- Write a program to print Astrik Pyramid.

Code1:- #include<iostream>
using namespace std;
int main(){
int n;
cout<<"Enter a number of rows:-";
cin>>n;

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


for(int j = 1; j <= i; j++) {
cout << "*";
}
cout << "\n";
}
return 0;
}

Code2:- #include <iostream>


using namespace std;

int main() {

int n;

cout << "Enter number of rows: ";


cin >> n;

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


for(int j = 1; j <= i; ++j) {
cout << "* ";
}
cout << endl;
}

return 0;
}

Code3:- #include<iostream>
using namespace std;
int main(){
int n,j,k;
cout<<"Enter a number of rows:-";
cin>>n;

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


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

*********************************************************************
Q.2 Write a program to print Number Pyramid up to n number
of rows.
Code:- #include <iostream>
using namespace std;

int main() {

int n;

cout << "Enter number of rows:- ";


cin >> n;

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


for(int j = 1; j <= i; j++) {
cout <<j<<" ";
}
cout << endl;
}

return 0;
}

***********************************************************************
Q.3 Write a program to print the following outputs using for
loops.
Code:- #include <iostream>

using namespace std;

int main() {

int n;

cout << "Enter number of rows:- ";


cin >> n;

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


for(int j = 1; j <= i; j++) {
cout <<i<<" ";
}
cout << endl;
}

return 0;
}

************************************************************************
************************************************************************

You might also like