CP Lab 5 Ex 1-5
CP Lab 5 Ex 1-5
Lab
Semester BS (CS) – 01
Yahya
02-134211-006
Lab 5
EXERCISE 1
#include <iostream>
using namespace std;
Int main ()
{
int x, y, z, rows;
cout << "Enter number of rows : ";
cin >> rows;
#include <iostream>
using namespace std;
int main ()
{
int i, j, r;
cout << "Enter number of rows : ";
cin >> r;
for (i = 0; i <= r; i++) {
for (j = 1; j <= r - i; j++) {
cout << " ";
}
for (j = 1; j <= 2 * i - 1; j++) {
cout << "*";
}
cout << endl;
}
for (i = r - 1; i >= 1; i--) {
for (j = 1; j <= r - i; j++) {
cout << " ";
}
for (j = 1; j <= 2 * i - 1; j++) {
cout << "*";
}
cout << endl;
}
system ("pause");
return 0;
}
#include<iostream>
using namespace std;
int main ()
{
int rows;
cout << "Enter the number of rows : ";
cin >> rows;
4. Write a C++ program to display such a pattern for n number of rows using a
number that will start with the number 1 and a last number of each row will be 1.
#include <iostream>
using namespace std;
int main ()
{
int rows, i = 1;
cout << "Enter number of rows : ";
cin >> rows;
for (int x = 0; x < rows; x++) {
for (int a = 1; a <= rows - x; a++) {
cout << " ";
}
for (int y = 1; y <= x; y++) {
cout << y;
}
for (int y = x - 1; y >= 1; y--) {
cout << y;
}
cout << endl;
}
system ("pause");
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
int x, y, n, b;
char alph = 'A';
int c = 1;
cout << "Enter the number of the last letter : ";
cin >> n;
for (x = 1; x <= n; x++) {
for (b = 1; b <= n - x; b++)
cout << " ";
for (y = 0; y <= (c / 2); y++)
{
cout << alph++ << " ";
}
alph = alph - 2;
for (y = 0; y < (c / 2); y++)
{
cout << alph-- << " ";
}
c = c + 2;
alph = 'A';
cout << endl;
}
system ("pause");
return 0;
}