0% found this document useful (0 votes)
9 views11 pages

0 Okmnb

The document contains C++ code snippets that use for loops to print patterns. Question 1 prints a 4x7 grid of asterisks. Question 2 prints ascending asterisk patterns where the number of asterisks increases by 2 each line. Question 3 part A prints a triangle of ascending asterisks, part B prints a descending triangle. Question 4 is similar but prints hollow triangles. Later questions print other patterns like descending numbers or boxes using conditions and nested for loops.

Uploaded by

daniyalalismh
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)
9 views11 pages

0 Okmnb

The document contains C++ code snippets that use for loops to print patterns. Question 1 prints a 4x7 grid of asterisks. Question 2 prints ascending asterisk patterns where the number of asterisks increases by 2 each line. Question 3 part A prints a triangle of ascending asterisks, part B prints a descending triangle. Question 4 is similar but prints hollow triangles. Later questions print other patterns like descending numbers or boxes using conditions and nested for loops.

Uploaded by

daniyalalismh
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/ 11

ITC LAB TASK # 8

Q1
#include <iostream>
using namespace std;
int main ()
{
int x=1;
int y=1;

for (x=1;x<=4;x++)
{
for (y=1;y<=7;y++)
{
cout<<" * ";
}
cout<<endl;
}
system("pause");
return 0;
}

Q2
#include <iostream>
using namespace std;
int main ()
{
int x=1;
int y=1;

for (x=0;x<=7;)
{
x=x+2;
for (y=1;y<x;y++)
{
cout<<" * ";
}
cout<<endl;
}
system("pause");
return 0;
}

Q3
(A)
#include <iostream>
using namespace std;
int main ()
{
int x=1;
int y=1;

for (x=1;x<=7;x++)
{
for (y=1;y<x;y++)
{
cout<<" * ";
}
cout<<endl;
}
system("pause");
return 0;
}

(B)
#include <iostream>
using namespace std;
int main ()
{
int x=7;
int y=7;

for (x=7;x>=0;x--)
{
for (y=7;y>=x;y--)
{
cout<<" * ";
}
cout<<endl;
}
system("pause");
return 0;
}
Q4
(A)
#include <iostream>
using namespace std;
int main ()
{
int x=7;
int y=7;

for (x=7;x>=1;x--)
{
for (y=1;y<x;y++)
{
cout<<" * ";
}
cout<<endl;
}
system("pause");
return 0;
}

(B)
#include <iostream>
using namespace std;
int main ()
{
int x=7;
int y=7;

for (x=7;x>=1;x--)
{
for (y=1;y<x;y++)
{
cout<<" * ";
}
cout<<endl;
}
system("pause");
return 0;
}

Q5
(A)
#include <iostream>
using namespace std;
int main ()
{
int x=2;
int y=1;

for (x=2;x<=6;x++)
{
for (y=1;y<x;y++)
{
cout<< y ;
}
cout<<endl;
}
system("pause");
return 0;
}

(B)
#include <iostream>
using namespace std;
int main ()
{
int x=2;
int y=1;

for (x=6;x>1;x--)
{
for (y=1;y<x;y++)
{
cout<< y ;
}
cout<<endl;
}
system("pause");
return 0;
}
Q6
#include <iostream>
using namespace std;
int main ()
{
int x=2;
int y=1;

for (x=5;x>=0;x--)
{
for (y=x;y>0;y--)
{
cout<< y ;
}
cout<<endl;
}
system("pause");
return 0;
}

Q16
(A)

#include <iostream>
using namespace std;
int main ()
{
int x=1;
int y=0;

for (x=1;x<=7;x++)
{
for (y=0;y<x;y++)
{
cout<< x ;
}
cout<<endl;
}
system("pause");
return 0;
}

(B)
#include <iostream>
using namespace std;
int main ()
{
int x=1;
int y=0;

for (x=7;x>=1;x--)
{
for (y=0;y<x;y++)
{
cout<< x ;
}
cout<<endl;
}
system("pause");
return 0;
}

Q11
#include <iostream>
using namespace std;
int main()
{
int rows = 10;
int columns = 15;
for (int i = 1; i <= rows; ++i)
{
for (int j = 1; j <= columns; ++j)
{
if (i == 1 || i == rows || j == 1 || j == columns)
{
cout << "@";
}
else
{
cout << " ";
}
}
cout << endl;
}
system("pause");
return 0;
}

Q15
#include <iostream>
using namespace std;
int main()
{
int rows = 5;
for (int x = 1; x <= rows; ++x)
{
for (int y = 1; y <= x; ++y)
{
cout << x * y << " ";
}
cout << endl;
}
system("pause");
return 0;
}

Q8
#include <iostream>
using namespace std;
int main()
{
int rows = 4;
int columns = 7;
for (int i = 1; i <= rows; ++i)
{
for (int j = 1; j <= columns; ++j)
{
if (i == 1 || i == rows || j == 1 || j == columns)
{
cout << "*";
}
else
{
cout << " ";
}
}
cout << endl;
}
system("pause");
return 0;
}

You might also like