Cross pattern program in C

Cross pattern program in C

Question:

Cross pattern program in C. Write a program to print the x-cross pattern for odd length. Must write this pattern program in C.

Pattern program logic:

  • Get the odd length input from the user.
  • Then insert the characters from top to bottom diagonally.
  • And insert the characters from bottom to top also in a diagonal position.
  • Then print the pattern.

Algorithm:

  1. Get the input string from the user.
  2. Then checks the diagonal position of the array and insert into it from top to bottom.
  3. And then checks the diagonal position from bottom to top to insert the string.
  4. At last, prints the array to display pattern.

Program:

include<stdio.h>
void main()
{
    int i,j,n,x,y,m=0;
    char a[20],c[10][10];
    clrscr();
    printf("enter the word with lenth odd:");
    gets(a);
    n=strlen(a);
    for(i=0;i<n;i++) \\insert into array from top to bottom
    {
       for(j=0;j<n;j++)
       {
	  if(i==j)\\ assign values to array only when i&j are equal otherwise prints null
	  {
	      c[i][j]=a[m];
	      m++;
	  }
	  else
	  {
	      c[i][j]='\0';
	  }
       }
    }
    i=n-1;
    m=0;
    for(j=0;j<n;j++)\\insert into array from bottom to top
    {
	c[i][j]=a[m];
	i--;
	m++;
    }
    for(i=0;i<n;i++)\\prints the cross word
    {
	for(j=0;j<n;j++)
	{
	    printf("%c",c[i][j]);
	}
	printf("\n");
    }
    getch();
}

You might also like..

1[0]1 Pattern Count | Samsung

Follow For Instant Updates

Join WhatsApp Group: link
Join our Telegram Channel: link
Like our Facebook Page:  link
Subscribe to our Youtube channel: link

Vignesh

A Computer Science graduate who likes to make things simpler. When he’s not working, you can find him surfing the web, learning facts, tricks and life hacks. He also enjoys movies in his leisure time.
0 0 votes
Article Rating
Subscribe
Notify of
guest
5.4K Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
5.4K
0
Would love your thoughts, please comment.x
()
x