I Made Krisna's Times My Way to Write the Times

16Oct/110

Draw a “stdio” Square Shape C Source Code

Working in a one of biggest electronics manufacturer in the world that didn't make my training comes to advanced level. I've learn again from the bottom. Of course the language used is native-C which the founder passed away recently...

One of the simplest thing is using looping for drawing some shapes and in this post it will be a square shapes. The easiest shape i think. What we nee d just a nested loop for drawing the rows (outer loop) and the cell or column (inner loop) which loop with the same number (square has same size for width/column and height/row).

#include "stdio.h"
#include "conio.h"

int main()
{
    int side;
    printf("Square's Side Size: ");
    scanf("%d", &side);    

    printf("\n");

    //Row Generation
    for (int i=0;i<side;i++)
    {
        //Column Generation
        for (int j=0;j<side;j++)
        {
            //Print * at each cell
            printf("*");
        }
        //Go to next row
        printf("\n");
    }

    getch();
    return 0;
}

That's all.... I'll post other shapes soon :D

Related posts:

  1. Draw a “stdio” BL Right-Angled Triangle C Source Code
  2. Tower of Hanoi C Source Code
  3. Knight’s Tour C Source Code
  4. Hello World MPI C Source Code
  5. Matrix-Vector Multiplication MPI C Source Code
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.