So, I have solved void pattern 2. Void pattern 1 I am having a bit of trouble be
ID: 3735936 • Letter: S
Question
So, I have solved void pattern 2. Void pattern 1 I am having a bit of trouble being able to turn my center column in to exponents of 2. Not exactly sure how to do it, and a pointer in the right direction would help a ton
Programming Questions: 01 (Display numbers in a pyramid pattern). Using nested loop, write a complete and commented C++ program using patternl function and pattern2 function to print the following patterns: void pattern2 (int rows 12 48 16 8 4 2 1 1 24 8 16 32 16 8 2 1 1 2 4 8 16 32 64 32 16 8 42 1 1 2 4 8 16 32 64 128 64 32 16 84 2 1 Make sure that your program prompts the user to enter number of rows.Explanation / Answer
// C++ code to demonstrate star pattern
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
// Function to demonstrate printing pattern
void triangle(int n)
{
// number of spaces
int k = 4*n-4;
int l=0;
// outer loop to handle number of rows
// n in this case
for (int i=0; i<n; i++)
{
// inner loop to handle number spaces
// values changing acc. to requirement
for (int j=0; j<k; j++)
cout <<" ";
// decrementing k after each loop
k = k - 4;
// inner loop to handle number of columns
// values changing acc. to outer loop
l=0;
for (int j=0; j<=2*i; j++ )
{
// printing stars
if(j<i){
cout.width(4);
cout<<(int)pow(2,l++);}
else{
cout.width(4);
cout <<(int)pow(2,l--);
}
}
// ending line after each row
cout << endl;
}
}
// Driver Function
int main()
{
int n = 8;
triangle(n);
return 0;
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.