In hình sao ra màn hình

Yêu cầu:

Dùng vòng lặp for, in ra màn hình các hinh vẽ sau:

1.

*
**
***
****
*****

/************************************************************
* Author: VNCODING
* History 
* 2014/03/27 first create VNCODING
*************************************************************/
#include <stdio.h>
#include <conio.h>

void main()
{
    int i, j;
    for(i = 0; i < 5; i++)
    {
        for(j = 0; j <= i; j++)
            printf("*");
        printf("\n");
    }
    getch();
}

2.

*****
****
***
**
*
/************************************************************
* Author: VNCODING
* History 
* 2014/03/27 first create VNCODING
*************************************************************/
#include <stdio.h>
#include <conio.h>

void main()
{
    int i, j;
    for(i=0; i < 5; i++)
    {
        for(j = 4; j >= i; j--)
            printf("*");
        printf("\n");
    }
    getch();
}

3.

*********
*********
*********
*********
*********
/************************************************************
* Author: VNCODING
* History 
* 2014/03/27 first create VNCODING
*************************************************************/
#include <stdio.h>
#include <conio.h>

void main()
{
    int i, j;
    for(i = 0; i < 5; i++)
    {
        for(j = 0; j <= 8; j++)
        printf("*");
        printf("\n");
    }
    getch();
}

4.

*
**
***
****
*****
*****
****
***
**
*

/************************************************************
* Author: VNCODING
* History 
* 2014/03/27 first create VNCODING
*************************************************************/
#include <stdio.h>
#include <conio.h>

void main()
{
    int i, j;
    for(i = 0; i < 5; i++)
    {
        for(j = 0; j <= i; j++)
            printf("*");
        printf("\n");
    }
    for(i = 0; i < 5; i++)
    {
        for(j = 4; j >= i; j--)
            printf("*");
        printf("\n");
    }
    getch();
}

5.

    *
   **
  ***
 ****
*****

/************************************************************
* Author: VNCODING
* History 
* 2014/03/27 first create VNCODING
*************************************************************/
#include <stdio.h>
#include <conio.h>

void main()
{
    int i, j;
    for(i = 0; i < 5; i++)
    {
        for(j = 4 - i; j > 0; j--)
            printf(" ");
        for(j = 0; j <= i; j++)
            printf("*");
        printf("\n");
    }
    getch();
}

6.

      *
     ***
    *****
   *******
  *********
   *******
    *****
     ***
      *
/************************************************************
* Author: VNCODING
* History 
* 2014/03/27 first create VNCODING
*************************************************************/
#include <stdio.h>
#include <conio.h>

void main()
{
    int i, j;
    int range = 0;
    for(i = 1; i <= 9; i++)
    {
        for(j = 1; j <= 9; j++)
        if((j >= 5 - range) && (j <= 5 + range))
            printf("*");
        else
            printf(" ");
        if(i >= 5)
            range -= 1;
        else
            range += 1;
        printf("\n");
    }
    getch();
}

1 Comment on In hình sao ra màn hình

Leave a Reply

Your email address will not be published.

*