Answer to Question #305893 in C++ for Magisk

Question #305893

Instructions:


1. In the code editor, you are provided with a main() function that asks the user for an integer input n, and passes this value to the function call of the generatePattern() function.


2. Your task is to implement this generatePattern() function which has the following description:


Return type - void


Function name - generatePattern


Parameters - 1 integer n


Description - this function prints a triangular pattern of letter T's based on the value of n. For more information, refer to the output in the test cases


3.DO NOT EDIT ANYTHING IN THE MAIN



Input



1. Integer n



This is the given code:



#include <iostream>


using namespace std;



int main(void) {


int n;



cout << "Enter n: ";


cin >> n;



generatePattern(n);



return 0;


}

1
Expert's answer
2022-03-04T04:04:41-0500
using namespace std;


/*
	1. In the code editor, you are provided with a main() function that asks the user for an integer input n, and passes this value to the function call of the generatePattern() function.
	2. Your task is to implement this generatePattern() function which has the following description:
	Return type - void
	Function name - generatePattern
	Parameters - 1 integer n
	Description - this function prints a triangular pattern of letter T's based on the value of n. 
	For more information, refer to the output in the test cases
	3.DO NOT EDIT ANYTHING IN THE MAIN
	Input
	1. Integer n
	This is the given code:
*/
#include <iostream>
using namespace std;


void generatePattern(int n)
{
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<i;j++)	cout<<"1 ";
		cout<<"\n";
	}
}

int main(void) 
{
	int n;
	cout << "Enter n: ";
	cin >> n;
	generatePattern(n);
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog