Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C + + nested loops to generate the following patterns: Write a program t

ID: 3822241 • Letter: W

Question

Write a C + + nested loops to generate the following patterns: Write a program that asks the user to type and fill up an integer array of size 7. The program must compute and write how many integers are less than or equal to 10. Write a program that asks the user to type and fill up an integer array of size 10. The program must compute and write the largest element in the array and prints the index at which that element was found. Write a C + + program that takes a decimal integer number and displays its equivalent value in binary format.

Explanation / Answer

Problem 2:

#include <iostream>

using namespace std;

void pattern1(int n)
{
for(int i = 1; i <= n; i++)
{
if (i % 2 == 1)
{
for(int j = 1; j <= i; j++)
{
cout << i << " ";
}
cout << endl;
}
else
{
for(int j = 1; j <= i; j++)
{
cout << "# ";
}
cout << endl;
}
}
}

void pattern2(int n)
{
for(int i = 1; i <= n; i++)
{
if (i % 3 == 1)
{
for(int j = n; j >= i; j--)
{
cout << "# ";
}
cout << endl;
}
else if(i % 3 == 2)
{
for(int j = n; j >= i; j--)
{
cout << j << " ";
}
cout << endl;
}
else
{
for(int j = n; j >= i; j--)
{
cout << "$ ";
}
cout << endl;
}
}
}

void pattern3(int n)
{
for(int i = 1; i <= n; i++)
{
if (i % 2 == 1)
{
for(int j = 2*n; j > 2*i; j--)
{
cout << " ";
}
for(int j = i; j > 0; j--)
{
cout <<(i+1) << " ";
}
cout << endl;
}
  
else
{
for(int j = 2*n; j > 2*i; j--)
{
cout << " ";
}
for(int j = 1; j <= i; j++)
{
cout << "# ";
}
cout << endl;
}
}
}

void pattern4(int n)
{
for(int i = 1; i < n; i++)
{
for(int j = 1; j <= i; j++)
{
cout << "# ";
}
for(int j = i+1; j <= n; j++)
{
cout << "$ ";
}
cout << endl;
  
}
}

void pattern5(int n)
{
for(int i = 1; i < n; i++)
{
for(int j = 1; j < i; j++)
{
cout << "# ";
}
cout << "$ ";
for(int j = i+1; j < n; j++)
{
cout << "# ";
}
cout << endl;
  
}
}


int main()
{
pattern1(7);
cout << endl;
pattern2(7);
cout << endl;
pattern3(7);
cout << endl;
pattern4(6);
cout << endl;
pattern5(6);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote