Lab Task 8 Zohaib Yasin f219658
Lab Task 8 Zohaib Yasin f219658
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;
Question no 4
#include <iostream>
using namespace std;
int main()
{
int space, size;
{
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;
{
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:
{
}
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;
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 << " ";