Write a function that accepts a character ch and a number n as arguments. The function then displays an n x n grid filled with ch. Use the function in a program.
#include<stdio.h>
#include<stdlib.h>
void grid(char ch, int n);
int main()
{
int n;
char ch;
printf("Enter a char : ");
scanf("%c",&ch);
printf("Enter a number : ");
scanf("%d",&n);
grid(ch,n);
}
void grid(char ch, int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%c ",ch);
}
printf("\n");
}
}
Comments
Leave a comment