This is the question from spoj . The question is to print a chess board like pattern with asterisk(*) and dot(.) starting with * The link for the question is given below:
spoj.com/problems/CPTTRN1
And here is my code.
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int l,c,i,j;
scanf("%d %d",&l,&c);
int arr[l][c];
for(i=0;i<l;i+=2)
{
for(j=0;j<c;j+=2)
{
arr[i][j]='*';
}
}
for(i=1;i<l;i+=2)
{
for(j=1;j<c;j+=2)
{
arr[i][j]='.';
}
}
for(i=0;i<l;i++)
{
for(j=0;j<c;j++)
{
printf("%c",arr[i][j]);
}
printf("\n");
}
}
return 0;
}
But I am not getting the answer. Also I am getting other characters other than dot and asterisk.
What is wrong in my code?
Also can't we use 2d arrays for printing patterns?
Aucun commentaire:
Enregistrer un commentaire