I want print the pattern and I have looked for many tutorials but didn't found anything like this.There are many patterns available but I don't know how to use the array characters for the same.
the pattern I want to print is:
012210
01 10
0 0
01 10
012210
Here is my program for this pattern:
#include <stdio.h>
int main()
{
int i, j, n;
scanf("%d", &n);
// upper half of the pattern
for(i = 0; i < n; i++)
{
for(j = 0; j < (2 * n); j++)
{
if(i + j <= n - 1) // upper left triangle
printf("%d",j);
else
printf(" ");
if((i + n) <= j) // upper right triangle
printf("%d",j);
else
printf(" ");
}
printf("\n");
}
// bottom half of the pattern
for(i = 0; i < n; i++)
{
for(j = 0; j < (2 * n); j++)
{
if(i >= j) //bottom left triangle
printf("%d",j);
else
printf(" ");
if(i >= (2 * n - 1) - j) // bottom right triangle
printf("%d",j);
else
printf(" ");
}
printf("\n");
}
return 0;
}
As in the question, I want the user to input in an array and according to the values the the array,the pattern is formed.Please help me on this.Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire