Thursday, July 12, 2012

Pattern Square

Write a program to output this pattern in C?



1:  #include<stdio.h>  
2:  int main() {  
3:       int col,row;  
4:       for(row = 0 ; row < 5 ; row++) {  
5:             for(col = 0 ; col < 5 ; col++) {  
6:                 if(row == 0 || row == 4) {  
7:                         printf("* ");  
8:                  }  
9:                  else {  
10:                        if(col == 0 || col == 4) {  
11:                            printf("* ");  
12:                         }  
13:                         else {  
14:                             printf(" ");  
15:                         }  
16:                  }  
17:             }  
18:             printf("\n");  
19:        }  
20:  }   

Output:-  






Note:- You can change the value of row and col to increase or decrease the size of pattern...  

No comments: