Print a letter x time per line in total y number of lines - C String

C examples for String:String Function

Description

Print a letter x time per line in total y number of lines

Demo Code

#include <stdio.h>

void printgrid(char ch, unsigned int cols, unsigned int rows);

int main(void)
{
  char ch;//from w  w  w.  ja v  a 2 s . co m
  int rows, cols;

  printf("Enter a character, number of rows and number of columns: ");
  
  while (scanf("%c %u %u", &ch, &rows, &cols) == 3){
    printgrid(ch, cols, rows);
    printf("Enter a character, number of rows and number of columns: ");
  }

  return 0;
}

void printgrid(char ch, unsigned int cols, unsigned int rows)
{
  for (int i = 0; i < rows; i++)
  {
    for (int j = 0; j < cols; j++){
      putchar(ch);
    }
    putchar('\n');
  }
}

Result


Related Tutorials