Monday, July 1, 2013

C Programming: Empty Box

Leave a Comment
C Programming: Empty Box. This program shows you how to make an empty box. There are two programs here, first one is not empty and the second is empty.


#include <stdio.h>
#include <conio.h>

int main()
{
    int r, c, row, col;
   
    printf("Enter number of rows: ");
    scanf("%d", &row);
    printf("Enter number of columns: ");
    scanf("%d", &col);
    printf("\n\n");
    for(r = 0; r < row; r++)
    {
          for(c = 0; c < col; c++)
          {
                printf("*");
          }
          printf("\n");
    }
   
    getch();
    return 0;
}

Here's the output of the program: 



Emtpy Box:
#include <stdio.h>
#include <conio.h>


int main()
{
    int r, c, row, col;
   
    printf("Enter number of rows: ");
    scanf("%d", &row);
    printf("Enter number of columns: ");
    scanf("%d", &col);
    printf("\n\n");


    for(r = 0; r < row; r++)
    {
          for(c = 0; c < col; c++)
          {
                if(r > 0 && r < row - 1)
                {
                     if(c > 0 && c < col - 1)
                     {
                          printf(" ");
                     }
                     else
                     {
                         printf("*");
                     }
                }
                else
                {
                    printf("*");
                }
          }
          printf("\n");
    }
   
    getch();
    return 0;
}

Here's the output of the program:


0 comments:

Post a Comment