Array is Acrostic Or Not In C Program - Source Code

#include <stdio.h>



int main()

    int i,j,n,k=1; 
    char a[100][100]; 
    printf("\nEnter the limit : ");
    scanf("%d", &n);
    printf("\nEnter the string : ");
    for(i=0;i<n;i++)
    {
        scanf("%s", a[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(a[i][j]!=a[j][i])
            {
                k=0;
            }
        }
    }
    if(k==1)
    {
        printf("\nGiven array is ACRostic ");
    }
    else
    {
        printf("\nGiven array is not acrostic ");
    }
    return 0;
}
Enter the limit : 3                                                                                                                                                           
                                                                                                                                                                              
Enter the string : ram                                                                                                                                                        ama                                                                                                                                                         mar                                                                                                                                                                           
                                                                                                                                                                              
Given array is ACRostic        

Enter the limit : 3                                                                                                                                                           
                                                                                                                                                                              
Enter the string : sam                                                                                                                                                        
ram                                                                                                                                                                           
mar                                                                                                                                                                           
                                                                                                                                                                              
Given array is not acrostic        



Comments