Hello, I\'m having a heck of a time with the following problem: Write a static m
ID: 3539453 • Letter: H
Question
Hello,
I'm having a heck of a time with the following problem:
Write a static method named xo that accepts an integer size as a parameter and prints a square of size by size characters, where all characters are "o" except that an "x" pattern of "x" characters has been drawn from the corners of the square. In other words, on the first line, the first and last characters are "x"; on the second line, the second and second-from-last characters are "x"; and so on. If 0 or less is passed for the size, no output should be produced.
The following table lists some calls to your method and their expected output:
I've been stuck on this problem for some time now, so I thought I'd ask for some help. I'd be grateful for any help that anyone can provide.
Thanks,
- B
Call xo(5); xo(8); xo(3); xo(1); xo(0); xo(12); xo(11); Output xooox oxoxo ooxoo oxoxo xooox xoooooox oxooooxo ooxooxoo oooxxooo oooxxooo ooxooxoo oxooooxo xoooooox xox oxo xox x xoooooooooox oxooooooooxo ooxooooooxoo oooxooooxooo ooooxooxoooo oooooxxooooo oooooxxooooo ooooxooxoooo oooxooooxooo ooxooooooxoo oxooooooooxo xoooooooooox xooooooooox oxoooooooxo ooxoooooxoo oooxoooxooo ooooxoxoooo oooooxooooo ooooxoxoooo oooxoooxooo ooxoooooxoo oxoooooooxo xooooooooox
Explanation / Answer
#include<stdio.h>
void main()
{
int n,i,j;
printf("Enter n value:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==j||(i+j)==n-1)
{
printf("X ");
continue;
}
printf("0 ");
}
printf(" ");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.