0% found this document useful (0 votes)
47 views14 pages

Lab Task 8 Zohaib Yasin f219658

This document contains 10 coding questions related to C++ programs for printing patterns like triangles, squares and pyramids. Each question includes the full source code for a program that uses loops to output the desired pattern based on user input for the size. The programs demonstrate the use of for loops, if-else statements, and switch cases to control the pattern printing logic.

Uploaded by

zohaiby 34
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)
47 views14 pages

Lab Task 8 Zohaib Yasin f219658

This document contains 10 coding questions related to C++ programs for printing patterns like triangles, squares and pyramids. Each question includes the full source code for a program that uses loops to output the desired pattern based on user input for the size. The programs demonstrate the use of for loops, if-else statements, and switch cases to control the pattern printing logic.

Uploaded by

zohaiby 34
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
You are on page 1/ 14

Lab Task 8

Name
Zohaib Yasin
Roll no
F21-9658
Section
BSSE B

Question no 1
#include<iostream>
using namespace std;
int main()
{
int size;
cout << "Enter The size of Triangle = ";
cin >> size;
for (int i = 1; i <= size; ++i)
{
for (int j = 1; j <= i; ++j)
{
cout << "*";
}
cout << endl;
}
system("Pause");
return 0;
}
Question no 2
#include<iostream>
using namespace std;
int main()
{
int size;
cout << "Enter The size of Triangle = ";
cin >> size;
for (int i = 1; i <= size; ++i)
{
for (int j = size; j >= i; --j)
{
cout << "*";
}
cout << endl;
}
system("Pause");
return 0;
}

Question no 3
#include <iostream>
using namespace std;
int main()
{
int space, size;

cout << "Enter Size of Triangle = ";


cin >> size;

for (int i = 1, k = 1; i <= size; ++i, k = 1)


{
for (space = 1; space <= size - i; ++space)
{
cout << " ";
}
while (k <= i)
{
cout << " *";
++k;
}
cout << endl;
}
system("Pause");
return 0;
}

Question no 4
#include <iostream>
using namespace std;
int main()
{
int space, size;

cout << "Enter Size of Triangle = ";


cin >> size;

for (int i = 1, k = size; i <= size; ++i, k = size)


{
for (space = size; space >= size - i; --space)
{
cout << " ";
}
while (k >= i)

{
cout << " *";
--k;
}
cout << endl;
}
system("Pause");
return 0;
}
Question no 5
#include <iostream>
using namespace std;
int main()
{
int n, space, size;
cout << "Enter Number For Triangles = ";
cin >> n;
switch (n)
{
case 1:
{
cout << "Enter The size of Triangle = ";
cin >> size;
for (int i = 1; i <= size; ++i)
{
for (int j = 1; j <= i; ++j)
{
cout << "*";
}
cout << endl;
}

}
break;
case 2:
{
cout << "Enter The size of Triangle = ";
cin >> size;
for (int i = 1; i <= size; ++i)
{
for (int j = size; j >= i; --j)
{
cout << "*";
}
cout << endl;
}

}
break;
case 3:
{
cout << "Enter Size of Triangle = ";
cin >> size;
for (int i = 1, k = 1; i <= size; ++i, k = 1)
{
for (space = 1; space <= size - i; ++space)
{
cout << " ";
}

while (k <= i)
{
cout << " *";
++k;
}
cout << endl;
}
}
break;
case 4:
{
cout << "Enter Size of Triangle = ";
cin >> size;

for (int i = 1, k = size; i <= size; ++i, k = size)


{
for (space = size; space >= size - i; --space)
{
cout << " ";
}
while (k >= i)

{
cout << " *";
--k;
}
cout << endl;
}
}
break;
default:
cout << "You have Entered an Invalid Number";
}

system("Pause");
return 0;
}
Question no 6
#include <iostream>
using namespace std;
int main()
{
int n, size;

cout << "Enter Number 1 For Square with Astarique \n Enter Number 2 For Square
with Numbers in Increasing Order \n Enter Number 3 For Square with Number in
D3creasi9ng Order" << endl;
cout << "Enter Number = ";
cin >> n;
switch (n)
{
case 1:
{
cout << "Enter Size of Square = ";
cin >> size;
for (int i = 1; i <= size; ++i)
{
for (int j = 1; j <= size; ++j)
{
cout << "*";
}
cout << endl;
}
}
break;
case 2:
{
cout << "Enter The Size of Square = ";
cin >> size;
for (int i = 1; i <= size; i++)
{
for (int j = 1; j <= size; j++)
{
cout << i << " ";
}
cout << endl;
}
}
break;
case 3:
{
cout << "Enter The Size of Square = ";
cin >> size;
for (int i = size; i >= 1; i--)
{
for (int j = 1; j <= size; j++)
{
cout << i << " ";
}
cout << endl;
}
}
break;
default:
cout << "You have Entered an Invalid Number"<<endl;
}

system("Pause");
return 0;
}
Question no 7

#include<iostream>
using namespace std;
int main()
{
int number,size;
cout << "Enter Number 1 for Triangle With Astraic" << endl;
cout << "Enter Number 1 for Triangle With Number in Increasing Order" << endl;
cout << "Enter Number 1 for Triangle With in Decreasing Order" << endl;
cout << "Enter Number = ";
cin >> number;
switch (number)
{
case 1:
{
cout << "Enter the size of Teiangle = ";
cin >> size;
for (int i = 1; i <= size; i++)
{
for (int j = 1; j <= i; j++)
{
cout << "* ";
}
cout << endl;
}
}
break;
case 2:
{

cout << "Enter the size of Teiangle = ";


cin >> size;
for (int i = 1; i <= size; i++)
{
for (int j = 1; j <=i ; ++j)
{
cout << j<<" ";
}
cout << endl;
}
}
break;
case 3:
{

cout << "Enter the size of Teiangle = ";


cin >> size;
for (int i = 1; i <= size; ++i)
{
for (int j = size; j >= i; --j)
{
cout << j << " ";
}
cout << endl;
}
}
break;

}
system("Pause");
return 0;
}
Question no 8
#include<iostream>
using namespace std;
int main()
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= 5; j++)
{
cout << i << " ";
}
cout << endl;
}
cout << endl;
//2
for (int i = 1; i <= 5; ++i)
{
for (int j = 1; j <= 5; ++j)
{
cout << j << " ";
}
cout << endl;
}
cout << endl;
//3
for (int i = 5; i >= 1; i--)
{
for (int j = 1; j <= 5; j++)
{
cout << i << " ";
}
cout << endl;
}
cout << endl;
//4
for (int i = 1; i <= 5; ++i)
{
for (int j = 5; j >= 1; --j)
{
cout << j << " ";
}
cout << endl;
}
cout << endl;

system("Pause");
return 0;
}

Question no 9 (a)
#include <iostream>
using namespace std;
int main()
{
int space, size;
cout << "Enter The Size of Paramid = ";
cin >> size;

for (int i = 1, k = 0; i <= size; ++i,k=0)


{
for (space = 1; space <= size -i; ++space)
{
cout << " ";
}
while (k <= 2 * i - 1)
{
cout << "* ";
++k;
}
cout << endl;
}

system("Pause");
return 0;
}

Question no 9 (b)
#include <iostream>
using namespace std;
int main()
{
int space, size;
cout << "Enter The Size of Paramid = ";
cin >> size;
for (int i = size; i >= 1; --i)
{
for (int space = 0; space < size - i; ++space)
cout << " ";

for (int j = i; j <= 2 * i - 1; ++j)


cout << "* ";

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


cout << "* ";

cout << endl;


}
system("Pause");
return 0;
}
Question no 10
#include <iostream>
using namespace std;
int main()
{
int space, size;
cout << "Enter The Size of Paramid = ";
cin >> size;
for (int i = 1, k = 0; i <= size; ++i, k = 0)
{
for (space = 1; space <= size - i; ++space)
{
cout << " ";
}
while (k <= 2 * i - 1)
{
cout << "* ";
++k;
}
cout << endl;
}
for (int i = size; i >= 1; --i)
{
for (int space = 0; space < size - i; ++space)
cout << " ";

for (int j = i; j <= 2 * i - 1; ++j)


cout << "* ";

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


cout << "* ";

cout << endl;


}
system("Pause");
return 0;
}

You might also like