In the IPL season’s valedictory function the organizers have organized for a dance program. The dance has to be performed by men  along the points of the diagonals of the square of side ‘n’ and the females along points of the borders. The remaining positions are to filled by children. Can you please help them determine their respective positions by writing a program……???

Sample Input:
Enter the size of matrix:
4
Sample Output:
M F F M
F M M F
F M M F
M F F M

Sample Input:
Enter the size of matrix:
7
M F F F F F M
F M C C C M F
F C M C M C F
F C C M C C F
F C M C M C F
F M C C C M F
M F F F F F M

Program Code:
#include<stdio.h>
int  main()
{
    int n,i,j;
    printf("Enter the size of matrix:\n");
    scanf("%d",&n);
    char a[n][n];
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i==j)
            {
                a[i][j]='M';
            }
            else if(i+j==n-1)
            {
               a[i][j]='M'; 
            }
            else if(i==0 && (j>0 && j<n))
            {
                a[i][j]='F';
            }
            else if(j==0 && (i>0 && i<n))
            {
                a[i][j]='F';
            }
            else if(j==n-1 && (i>0 && i<n))
            {
                a[i][j]='F';
            }
            else if(i==n-1 && (j>0 && j<n))
            {
                a[i][j]='F';
            }
            else
            {
               a[i][j]='C'; 
            }
        }
    }
   for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            printf("%c ",a[i][j]);
        }
        printf("\n");
    }
    return 0;
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: