Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- square pattern with cross v1.c
- Program by Debottam Das
- https://www.facebook.com/debottam.das.121
- Enter any odd number of rows: 11
- output is :
- *
- # * #
- # # * # #
- # # # * # # #
- # # # # * # # # #
- * * * * * * * * * * *
- # # # # * # # # #
- # # # * # # #
- # # * # #
- # * #
- *
- */
- #include<stdio.h>
- void square_pattern_with_cross(int n)
- {
- int i, j, s, s1=0, s2=0, s3;
- s = n/2;
- s1 = s+1;
- s2 = s;
- s3 = s1;
- for(i=1; i<=((n/2)); i++)
- {
- for(j=1; j<=s1; j++)
- {
- if(j<=s && s!=0)
- {
- printf(" ");
- }
- else if (j == ((n/2)+1))
- {
- printf("* ");
- }
- else
- {
- printf("# ");
- }
- }
- s--;
- s1++;
- printf("\n");
- }
- for(i=1; i<=n; i++)
- {
- printf("* ");
- }
- printf("\n");
- s = 1;
- s1 = (n/2)+(n/2); // not s1 = n because of integer division !
- s2 = n/2;
- for(i=1; i<=s2; i++)
- {
- for(j=1; j<=s1; j++)
- {
- if(j<=s && s!=0)
- {
- printf(" ");
- }
- else if (j == ((n/2)+1))
- {
- printf("* ");
- }
- else
- {
- printf("# ");
- }
- }
- s++;
- s1--;
- printf("\n");
- }
- }
- void main(void)
- {
- int number_of_rows;
- printf("\n Enter any odd number of rows: ");
- scanf("%d",&number_of_rows);
- printf("\n");
- if(number_of_rows %2 == 0)
- {
- printf("\n SORRY! With even numbers this pattern is not possible. \n");
- return 1;
- }
- square_pattern_with_cross(number_of_rows);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement