Printing prismatic shapes with C language. Thank you!

Updated on technology 2024-08-08
16 answers
  1. Anonymous users2024-02-15

    I've solved this problem before, now I'll figure it out for you!!

    There are several ways to do this.

    The simplest way to do this is to use the printf function to output it line by line. Of course, you can also use the following method.

    But it's not so easy to understand.

    #include

    int main()

    char a='*';

    int i,j,k,n;

    j=1;record line number;

    i=1;Record the number of * signs per line.

    k=8;Record the number of spaces in each row.

    The n-value is used to temporarily save the k-value. Used in a for loop.

    while(j<=4)

    i=1+2*(j-1);

    k=8-2*j;

    n=k;for(;n>=0;n--)

    printf(" ");

    for(;i>=1;i--)

    printf("* ");

    printf("");

    j++;while(j<=7)

    i=7-2*(j-4);

    k=2*(j-4);

    n=k;for(;n>=0;n--)

    printf(" ");

    for(;i>=1;i--)

    printf("* ");

    printf("");

    j++;return 0;

    Attached is the method of using the printf function.

    #include

    int main()

    printf(" *");

    printf(" * n");

    printf(" * n");

    printf("* *n");

    printf(" * n");

    printf(" * n");

    printf(" *");

    return 0;

    If you don't understand, please contact me.

  2. Anonymous users2024-02-14

    I'll talk about the second, in fact, the first and the second ideas are the same.

    1.The outside for loop, use i to control the number of rows, the input integer is n, then the number of rows of the whole graph is 2*n-1, and the number of columns is the same, you can see, that is, the number of rows and the number of columns are the same, so the inner loop and the outer loop are both 2*n-1, if you don't believe it, you can check the number of rows and columns of the graph.

    is to control the lower half. Because 0<=j<=2*n-1, that is, j can be greater than n-1, or it can be smaller than the middle column of the real graph, and the whole graph is symmetrical about this column. When i = n, the principle is the same, as i increases, each row will be two fewer digits, and the position of the fewer digits will be symmetrical with respect to the middle column.

    Therefore, when abs(n-1-j)<2*n-1-i, i>=n, every time i increases by 1, 2*n-1-i will decrease by 1, abs(n-1-j) will decrease by two columns, and the two columns that are reduced are about intermediate symmetry, you can calculate whether this is the truth.

    Is there anything else you don't understand?

  3. Anonymous users2024-02-13

    I didn't write it, but I can still read it.

    You can use arithmetic to deduce the number of spaces and * in each line.

    And then there's the nasty simulation.

  4. Anonymous users2024-02-12

    #include

    #include

    #include

    int main()

    int i,j,k=1;

    for(i=0;i<10;i++,k+=2){for(j=0;j<10-i;j++)

    printf(" ");

    for(j=0;j

    Do you want to print a triangle, the above is to print a triangle**-Internet of Things School-Enterprise Alliance Technology Department.

  5. Anonymous users2024-02-11

    The pseudo-** method determines whether it is a leap year (the big year is not involved here), because you are not sure of the language you use.

    The return value is true, indicating that the year corresponding to the input parameter is a leap year. otherwise not a leap yearboolean whether it is a leap year (int year) elsereturn boo; }

  6. Anonymous users2024-02-10

    #include

    void main()

    for(i=4;i<=7;i++) print the bottom half} You can also take it up a bit and print an empty diamond. This one of mine is simple enough, just use the for loop.

  7. Anonymous users2024-02-09

    Haha, the second floor is right, a few lines of ** can be fully realized.

    I don't know if it's shorter than what I wrote.

    void main()}

  8. Anonymous users2024-02-08

    #include

    #include

    int main()

    for(i=1;i<=i;i++)

    for(k=k;k<=2*n;k++)

    printf("");

    m-=1;k+=1;

    i+=1;return 0;

    To you the first half ... Think for yourself about the second half ... All right?

  9. Anonymous users2024-02-07

    Please explain, who is going to explain to this master, is it so troublesome to write on the first floor? It would be nice to write simply.

  10. Anonymous users2024-02-06

    First of all, open the C language machine in your computer and create a new source file, as shown in the figure below.

    Then write **, as shown in the figure below, and the source ** is as follows: include Use C to loop to draw a diamond of numbers.

    Continue to enter **, as shown in the figure below, for(i=1; i<=n-1;i++) outputs the lower half of the triangle if(i==n-1)printf("1");else{for(t=1;t<=n-i;t++)

    Finally, click Compile and Run, as shown in the figure below, and then type n to see the result, diamond pattern.

  11. Anonymous users2024-02-05

    Loop output, as long as the number of spaces is determined.

    int main()

    for (j = 0; j < 2 * i+1; j++)printf("");

    for (i = 0; i < line - 1; i++)for (j = 0; j < 2 * line - 1 - i) -1; j++)

    printf("");

    system("pause");

    return 0;

    This one is a solid diamond-shaped **.

  12. Anonymous users2024-02-04

    *It is easier to understand the output with the following statements, mainly the nested statements of the loop structure play a role, pay attention to the increasing relationship between spaces and asterisks* and you can output as many lines as you need. Refining! #include ""

    void main()

    printf(" ");

    for(i=0;i<=n;i++)

  13. Anonymous users2024-02-03

    #include

    main()

    printf("");After the * of the ith line is output, the line wrap executes the loop of the i+1 line.

    The following procedure performs an inverted star triangle.

    for(i=0;i<(m-1)/2;i++) Remaining number of lines m-(m+1) 2=(m-1) 2

    printf("");}

  14. Anonymous users2024-02-02

    * Manhattan Distance Principle solves the output diamond problem.

    #include

    using namespace std;

    int main()

    cout<}return 0;}

  15. Anonymous users2024-02-01

    Tan Haoqiang's fourth edition of post-class question answers.

    #include

    int main()

    for(b=1;b<=2*i-1;b++) controls the number of * per row, printf("");

    Last 3 lines, bottom half.

    for(i=n-1;i>=1;i--) control the number of rows in the first four rows for(b=1; b<=2*i-1;b++) controls the number of * per row, printf("");

    printf("");

    return 0;}

  16. Anonymous users2024-01-31

    Extension: Print a diamond (method 1).

    #include

    main()

    for(row=6;row<10;row++)

Related questions
12 answers2024-08-08

Left shape and right sound: liver, shock, paste, mounting, outline, pine, reason, Yue, river, copper, ocean, nitrate. >>>More

7 answers2024-08-08

Note: I'm really sorry, but I read your question again, it may be a design problem with the equipment foundation. At that time, I did not understand the content of your question correctly, and I did it according to the budget, and now I have deleted the content and apologize to you for my recklessness. >>>More

5 answers2024-08-08

There are six main hand types:

1. Square hands, square hands are also known as gold-shaped hands, actual hands, and capable hands. Men and women with this hand shape advocate practicality rather than flashiness, abide by order, have a firm will, strong endurance, clean and self-love, can thrift and run a family without being comfortable, are pragmatic, can achieve great things and live a long life, but they are not decisive and tactful, stubborn, and have a tendency to be stingy, and have no arrogance. >>>More

8 answers2024-08-08

Tyson polygons and their properties.

The Dutch climatologist A. H. Thiessen proposed a method of calculating the average rainfall based on the rainfall of discretely distributed weather stations, that is, all adjacent weather stations were connected into triangles and made a vertical bisector on each side of these triangles, so that a number of vertical bisectors around each weather station were enclosed into a polygon. The intensity of rainfall in the area of this polygon is expressed by the intensity of rainfall at a unique weather station contained within this polygon, and this polygon is called a Tyson polygon. As shown in Figure 5-6-1, the polygon formed by the dotted line is the Tyson polygon. >>>More

17 answers2024-08-08

To change the value of a variable by passing a function, you must pass an address. Your program is passing the value of the variable swap(a,b); If you want to change the value of a variable, you must pass the address of the variable, or do it by a pointer, if it is an array, you can directly use the array name, but if it is an element of the array, you still need to use the address. Just change it like the one upstairs did him. >>>More