Tuesday, October 21, 2014

Print G patterns with C Language




                                         
                                                             
                                                  

#include<stdio.h>
#include<conio.h>

void main()
{
                        int i,n,j;
                        printf("\t enter value of n=");
                        scanf("%d",&n);
                        printf("\n\n");
                        for(i=0;i<n;i++)
                        {
                                    for(j=0;j<n;j++)
                                    {
                                                 if(i==0||j==0||(i==n-1&&j<=n/2+1)||(j==n-1&&i>=n/2)||(j==n/2+1&&i>=n/2)||(i==n/2&&j>=n/2+1))
                                                 {
                                                              printf("*");
                                                 }
                                                 else
                                                 {
                                                              printf(" ");
                                                 }
                                    }
                                     printf("\n");
              }
}


No comments:

Post a Comment