This is the example of c-programming. You can edit and compile code in your own way on clicking button. If you have better solution or you found any error on code, then give us suggestion.
Full Code:
Code Explanation :
This is the example of C program to print the solid rectangular shape using *
sign. Before going through the example, You must know about following topics.
Here, we use user defined function
to print solid rectangle. We also print hollow rectangle in this example below. In that example also, we use user defined function.
This is basic usage of function and for loop. May viewing this code, you will understand this example.
This same can be done without function.
Program to print solid rectangle without function
/* C program to print solid rectangle star pattern */ #include <stdio.h> int main() { int rows, columns, i, j; printf("nEnter the number of rows : "); scanf("%d", &rows); printf("nEnter the number of columns : "); scanf("%d", &columns); printf("n"); for (i = 1; i <= rows; i++) { for (j = 1; j <= columns; j++) { printf("*"); } printf("n"); } return 0; }
We are representing algorithm and flowchart according to the above code.
Algorithm
SETP 1 : Start SETP 2 : Declare variable rows,columns i and j SETP 3 : Read rows and columns SETP 4 : Initialize i = 1 and j = 1 SETP 5 : Repeat this process until i < rows and STEP 5.1 : Repeat this process until j <= columns STEP 5.1.1 : Print "*"; STEP 5.1.2 : j++; STEP 5.2 : Print "n" to break line STEP 5.3 : i++; STEP 6 : end
Flowchart

To print hollow rectangle
/* C program to print hollow rectangle star pattern */ #include <stdio.h> void hollow_rectangle(int, int); int main() { int rows, columns; printf("nEnter the number of rows : "); scanf("%d", &rows); printf("nEnter the number of columns : "); scanf("%d", &columns); printf("n"); hollow_rectangle(rows, columns); return 0; } /* Function to print hollow rectangle*/ void hollow_rectangle(int n, int m) { int i, j; for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { if (i==1 || i==n || j==1 || j==m) printf("*"); else printf(" "); } printf("n"); } }
This is same example as above. this program print holow rectangle as given below. you can compile using our IDE.
******************** * * * * * * * * * * ********************
May you understand this example. If you got any issue on understanding this example, then you can coment below. You will reply your with better solution.
Our example mainly covers following topics in any programing
- Basic Programs
- Number Programs
- Array Programs
- Matrix Programs
- Pattern Programs
- String Programs
- Tree Programs
- Singly Linked List Programs
- Circular Linked List Programs
- Doubly Linked List Programs
Here we share programs on various topics such as array strings, series area & volume of geometric figures, mathematical calculation algorithms for sorting & searching and much more.Our goal is to provide you with the perfect solution to all the programming problems you may have encountered either during interviews or in class assignments. If you don’t find what you are looking for then please drop a line in the comment section of example page or you can request from account page so that we can get it added to the below collection of programs. Happy Learning!!
If you are confident with the above programs and are able to successfully understand and run them without any problems then it is time for you to take a step further and learn comprehensive programming principles using examples and flow diagrams. Here is the link: Programming tutorial lists .
If you find this example helpful, don't forget to share it with your friends. And stay updated with us by subscribing adzetech.
If you find any code error or grammetical error then you can suggest for example improvement on clicking below button.
Check out these related examples:
- C Program to Find Largest Element in an Array
- C Program to Multiply Two Floating-Point Numbers
- C Program to Find the Length of a String
- C Program to Find Transpose of a Matrix
- [Two dimension array] C program to read matrix and print its diagonal
- C Program to Add Two Matrices Using Multi-dimensional Arrays
- C Program to Find ASCII Value of a Character
- C Program to Compute Quotient and Remainder
- C Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers
- C Program to Check Armstrong Number
Leave comment