Write a C program to print a block F using hash (#), where the F has a height of six characters and width of five characters.

Next

Approach-1:

  • In this approach we simply used printf() function from stdio.h header file.
  • We specified ‘#’ character in printf() function based on output pattern.
#include<stdio.h>
int main()
{
 	printf("#####\n");
 	printf("#\n");
 	printf("#\n");
 	printf("#####\n");
 	printf("#\n");
 	printf("#\n");
 	printf("#\n");
	return(0);
}

Approach-2:

  • In C programming, we can process and display the information in two dimensional format(rows and columns) using nested for loop.
  • Outer loop represents number of rows as we mentioned in the problem.
  • Inner loop represents number of columns(printing data of each row).
  • We use if condition inside the inner loop to break the row when required.
#include<stdio.h>
int main()
{
	int i, j;
	for(i=1 ; i<=6 ; i++)
	{
		for(j=1 ; j<=5 ; j++)
		{
			printf("#");
			if(i==2 || i==4 || i==5 || i==6)
				break;	
		}
		printf("\n");
	}
	return 0;
}
Next

Courses Enquiry Form