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

Part II: 2-Dimensional Array file name: lab1part2.cpp (10 points) Write a C++ fu

ID: 3541554 • Letter: P

Question

Part II: 2-Dimensional Array
file name: lab1part2.cpp
(10 points)
Write a C++ function, named DrawN(), that will receive a two-dimensional array of chars (size 10 x 10) as a parameter and assign the character

2-Dimensional Array file name: lab1part2.cpp Write a C++ function, named DrawN(), that will receive a two-dimensional array of chars (size 10 x 10) as a parameter and assign the character 'N' to each element in the first and last rows, and to each element in the diagonal from the upper right to the lower left (as displayed below). Test your function in main().

Explanation / Answer



#include<iostream>
using namespace std;
void DrawN(char a[10][10])
{
for(int i=0; i<10; i++)
{
for(int j=0; j<10; j++)
{
if(i==j) a[i][j] = 'N';
if(j==9 || j==0) a[i][j] = 'N';
}
}
}
int main()
{
char a[10][10] = {};
for(int i=0; i<10; i++)
{
for(int j=0; j<10; j++)
{
a[i][j]= ' ';
}
}
DrawN(a);
for(int i=0; i<10; i++)
{
for(int j=0; j<10; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}