C Program Side Length Example

How to write a C Program Side Length in C Programming Language ?


Solution For C Program :
#include <stdio.h>
#include <string.h>

void printChar(char c, int amount)
{
    int i;
    for (i = 0; i < amount; i++)
    {
        printf("%c", c);
    }
}

void printSquare(char c, unsigned sideLength, char hollow)
{
    int i;
    if (hollow == 'y')
    {
        printChar(c, sideLength);
        printf("\n");
        for (i = 0; i < sideLength - 2; i++)
        {
            printChar(c, 1);
            printChar(' ', sideLength - 2);
            printChar(c, 1);
            printf("\n");
        }
        printChar(c, sideLength);
        printf("\n");
    }
    else
    {
        for (i = 0; i < sideLength; i++)
        {
            printChar(c, sideLength);
            printf("\n");
        }
    }

    return;
}

int main()
{
    char print, hollow;
    unsigned sideLength;

    printf("Side length: ");
    scanf("%u", &sideLength);
    printf("Printed character: ");
    scanf("%s", &print);
    printf("Hollow (y/n): ");
    scanf("%s", &hollow);

    printSquare(print, sideLength, hollow);

    return 0;
}

Program related to C Programming Language :



  1. C Program Array Index Example
  2. C Program String - Alphabet Count Example
  3. C Program Character toupper() Example
  4. C Program Array Example: Average
  5. C Program Array Example: Reverse
  6. C Program if - while - for Example
  7. C Program Switch - Case Example
  8. C Program 0.1 + 0.2 != 0.3 Solved
  9. C Program if - else if - else Example
  10. C Program typedef Example
  11. C Program scanf & gets Example
  12. C Program Friend & Operator: Point2D Example
  13. C Program Friend & Operator: Vector Example
  14. C Program Recursion Example
  15. C Program File Input & Output Example
  16. C Program Structure Example-2
  17. C Program Structure Example
  18. C Program Pointer Example
  19. C Program Function Example
  20. C Program String Example
  21. C Program String Count Example
  22. C Program String Example
  23. C Program Character Example
  24. C Program Sort Example
  25. C Program sizeof & memcpy Example
  26. C Program Array Example
  27. C Program to Array
  28. C Program print fill zero & mod/div
  29. C Program Double, Float Equal
  30. C Program nested for
  31. C Program for
  32. C Program if
  33. C Program System
  34. C Program Operation
  35. C Program to printf & scanf
  36. Example C Program Cuda Malloc
  37. C Program Side Length


Learn More :