How can I draw this graph with 2 loops and 1 if statement?


revenge

How can I draw such a graph in C with 2 for loops and 1 if statement?

AAAAA
AAAAB
AAABB
AAAAB
AAAAA

I know I have to compare rows and columns, but I don't know how to get accurate results.

It must work for every number greater than 0 and less than 24.

What I have done so far is:

for (row = 1; row <= n; row++)
{
    for (column = 1; column <= n; column++)
    {
        if ( row >= column )
        {
            printf("A");
        }
        else
        {
            printf("B");
        }
    }
    printf("\n");
}

This gives me n=5:

ABBBB
AABBB
AAABB
AAAAB
AAAAA
Eugene Halca

Well done:

for (row = 1; row <= 5; row++)
{
    for (column = 1; column <= 5; column++)
    {
        if ( (row < column) && (column > 5 - row + 1) )
        {
            printf("B");
        }
        else
        {
            printf("A");
        }
    }
    printf("\n");
}

demo

explain:

Condition (row < column)"draw":

ABBBB
AABBB
AAABB
AAAAB
AAAAA

Condition (column > 5 - row + 1)"draw":

AAAAA
AAAAB
AAABB
AABBB
ABBBB

The combination of these conditions is your result.

Related


How can I draw this graph with 2 loops and 1 if statement?

revenge How can I draw such a graph in C with 2 for loops and 1 if statement? AAAAA AAAAB AAABB AAAAB AAAAA I know I have to compare rows and columns, but I don't know how to get accurate results. It must work for every number greater than 0 and less than 24.

How can I draw this graph with 2 loops and 1 if statement?

revenge How can I draw such a graph with 2 for loops and 1 if statement? AAAAA AAAAB AAABB AAAAB AAAAA I know I have to compare rows and columns, but I don't know how to get accurate results. It must work for every number greater than 0 and less than 24. What

How to draw a graph with two loops

phosphor Although this problem has been "solved" many times, it turns out that there is always another problem. Without the print function, it works fine, but I get the following result: Error in .subset2(x, i) : recursive indexing failed at level 2 What I'm

How to draw a graph with two loops

phosphor Although this problem has been "solved" many times, it turns out that there is always another problem. Without the print function, it works fine, but I get the following result: Error in .subset2(x, i) : recursive indexing failed at level 2 What I'm

How to draw a graph with two loops

phosphor Although this problem has been "solved" many times, it turns out that there is always another problem. Without the print function, it works fine, but I get the following result: Error in .subset2(x, i) : recursive indexing failed at level 2 What I'm

How to draw a graph with two loops

phosphor Although this problem has been "solved" many times, it turns out that there is always another problem. Without the print function, it works fine, but I get the following result: Error in .subset2(x, i) : recursive indexing failed at level 2 What I'm

How can I draw such a graph in Python?

Santos I want to draw a graph like the image below: I wrote the following code to plot the waveform for each time step. import matplotlib.pyplot as plt import numpy as np def u_0(x): a = 1.0/np.cosh(2.0*(x+8.0)) b = 1.0/np.cosh((x+1.0)) return 8.0

How can I draw this graph in Excel?

Pablo I have a CSV file with the following data This series has 500 rows. However, I need to plot whatever is on column A as the horizontal axis and whatever is on column B [0..499] as the vertical axis. I would like to label the horizontal axis values at ever

How can I draw a complete graph in R?

Mrsteve I want to draw complete graphs in R. How can I do this? I've only found one package on CRAN that has the ability to generate a full graph. But this package (i.e. "RnavGraph") is not installed but exits with error status. Further searching seems to be d

How can I draw this graph in R?

cooldood3490 I want to draw speedVS. Data are as follows:age Speed Age 15 <18 30 18-25 40 26-40 32 40+ How can I plot this as a scatterplot in R? I don't know how to do range. So far this is what I have. speed<-c(15,30,40,32) Peter Accu

How can I draw such a graph in Python?

Santos I want to draw a graph like the image below: I wrote the following code to plot the waveform for each time step. import matplotlib.pyplot as plt import numpy as np def u_0(x): a = 1.0/np.cosh(2.0*(x+8.0)) b = 1.0/np.cosh((x+1.0)) return 8.0

How can I draw this graph in Excel?

Pablo I have a CSV file with the following data This series has 500 rows. However, I need to plot whatever is on column A as the horizontal axis and whatever is on column B [0..499] as the vertical axis. I would like to label the horizontal axis values at ever

How can I draw this graph in R?

cooldood3490 I want to draw speedVS. Data are as follows:age Speed Age 15 <18 30 18-25 40 26-40 32 40+ How can I plot this as a scatterplot in R? I don't know how to do range. So far this is what I have. speed<-c(15,30,40,32) Peter Accu

I can't draw this graph

Dana Cassio Costa I've been trying to draw this graph all night. Please, can someone help me? Here's what I've done so far. The constant function is in the middle of the plot, not sure why, I can't add smaller ticks to the bottom and top of the plot. theta = c

I can't draw this graph

Dana Cassio Costa I've been trying to draw this graph all night. Please, can someone help me? Here's what I've done so far. The constant function is in the middle of the plot, not sure why, I can't add smaller ticks to the bottom and top of the plot. theta = c

I can't draw this graph

Dana Cassio Costa I've been trying to draw this graph all night. Please, can someone help me? Here's what I've done so far. The constant function is in the middle of the plot, not sure why, I can't add smaller ticks to the bottom and top of the plot. theta = c

I can't draw this graph

Dana Cassio Costa I've been trying to draw this graph all night. Please, can someone help me? Here's what I've done so far. The constant function is in the middle of the plot, not sure why, I can't add smaller ticks to the bottom and top of the plot. theta = c

I can't draw this graph

Dana Cassio Costa I've been trying to draw this graph all night. Please, can someone help me? Here's what I've done so far. The constant function is in the middle of the plot, not sure why, I can't add smaller ticks to the bottom and top of the plot. theta = c

How can I draw a legend for this graph with many features?

LAD: I have a matrix with Xonly 1 row as input . I have a matrix Ywith each row as the output of a function. If Ythere are 5 lines, then we have 5 different functions. I use the following code to plot all functions on the same graph: import numpy as np import

how can i draw graph in spring mvc in jsp using highchart

Francisco Gallardo: i want to draw graph in jsp unsando spring mvc and highchart but i still can't do it, i wait for your answer thanks My point, this is where I want to draw the graph, but the graph is not showing, it shows nothing <%@ taglib uri="http://java

How can I draw a legend for this graph with many features?

LAD: I have a matrix with Xonly 1 row as input . I have a matrix Ywith each row as the output of a function. If Ythere are 5 lines, then we have 5 different functions. I use the following code to plot all functions on the same graph: import numpy as np import

How can I draw a legend for this graph with many features?

LAD: I have a matrix with Xonly 1 row as input . I have a matrix Ywith each row as the output of a function. If Ythere are 5 lines, then we have 5 different functions. I use the following code to plot all functions on the same graph: import numpy as np import

How can I draw a linear regression line in this graph?

Lin Jian enter image description here How can I draw a linear regression line in this graph? Here is my code: import numpy as np import pandas_datareader.data as web import pandas as pd import datetime import matplotlib.pyplot as plt #get adjusted close price

How can I draw a control flow graph from this code?

learn math int main() { int i, grade = 0; printf (" Enter points: \n"); scanf ("%d", &i); if (i >= 50 && i <= 60) grade = 5; else if (i > 50 && i <= 60) grade = 6; else if (i > 60 && i <= 70) grade = 7; else if (i > 70 && i <= 80) g

How can I draw an energy ranking graph using Python?

twin penguins This is a typical energy ranking used in some published papers, and I am struggling to reproduce one for my data using Python (any matplotlib, sns, etc.). I structure the data in a Pandas dataframe like this: System Color_id Data1 Data2 Form I