Printing the patterns of number.
/*
printing the pattern as given below for given number--
3 3 3 3 3
3 2 2 2 3
3 2 1 2 3
3 2 2 2 3
3 3 3 3 3
*/
#include <stdio.h>
int main()
{
int n;
printf("Enter : ");
scanf("%d" , &n);
// Complete the code to print the pattern.
for (int i = 0; i < (2 * n) - 1; i++)
{
for (int j = 0; j < (2 * n) - 1; j++)
{
int min = i < j ? i : j;
min = min < (2 * n - j - 2) ? min : (2 * n - j - 2);
min = min < (2 * n - i - 2) ? min : (2 * n - i - 2);
int index = n - (min);
printf("%d " , index);
}
printf("\n");
}
return 0;
}
No comments:
Post a Comment