We have an N x N square grid.


We will paint each square in the grid either black or white.

If we paint exactly A squares white, how many squares will be painted black?

A and N are integers,

Print the number of squares that will be painted black.
C++

Respuesta :

Answer:

The solution in C++ is:

#include <iostream>

using namespace std;

int main(){

   int N, A;

   cout<<"Grids: ";    cin>>N;

   cout<<"White: ";    cin>>A;

   cout<<"Black: "<<N * N - A;

   return 0;

}

Explanation:

This declares N and A, as integers

   int N, A;

This gets inputs for N

   cout<<"Grids: ";    cin>>N;

This gets inputs for A, (the white grids)

   cout<<"White: ";    cin>>A;

This calculates and prints the number of black grids

   cout<<"Black: "<<N * N - A;

PS

From the question, we understand that the grid is N by N square grids.

This means that:

[tex]Total = N * N[/tex]

So, the number of black grids is:

[tex]Black = Total - A[/tex]