/**
* C program to print hollow square star pattern
x x x x x
x 0 0 0 x
x 0 0 0 x
x 0 0 0 x
x x x x x
*/
#include <stdio.h>
#include<conio.h>
void main()
{
int i, j, N;
/* Input number of rows from user */
printf("Enter number of rows: ");
scanf("%d", &N);
/* Iterate over each row */
for(i=1; i<=N; i++)
{
/* Iterate over each column */
for(j=1; j<=N; j++)
{
if(i==1 || i==N || j==1 || j==N)
{
/* Print star for 1st, Nth row and column */
printf("x");
}
else
{
printf("0");
}
}
/* Move to the next line/row */
printf("\n");
}
getch();
}
source:codeforwin.org
* C program to print hollow square star pattern
x x x x x
x 0 0 0 x
x 0 0 0 x
x 0 0 0 x
x x x x x
*/
#include <stdio.h>
#include<conio.h>
void main()
{
int i, j, N;
/* Input number of rows from user */
printf("Enter number of rows: ");
scanf("%d", &N);
/* Iterate over each row */
for(i=1; i<=N; i++)
{
/* Iterate over each column */
for(j=1; j<=N; j++)
{
if(i==1 || i==N || j==1 || j==N)
{
/* Print star for 1st, Nth row and column */
printf("x");
}
else
{
printf("0");
}
}
/* Move to the next line/row */
printf("\n");
}
getch();
}
source:codeforwin.org
No comments:
Post a Comment