#2 Diagonal & Sides of a Rectangle
Input: 7 (input should be an odd number only, else the desired output will not be obtained)
output:
Program For Diagonal & Slides of a Rectangle:
#include <stdio.h>
int main()
{
int i, j, n;
printf("Enter number:");
scanf("%d", &n); // 'n' must be odd
for(i = 0; i < n; i++)
{
for(j = 0; j < n; j++)
{
// left diagonal, right diagonal, top horizontal, bottom horizontal, left vertical, right vertical
if(i == j || i + j == n - 1 || i == 0 || i == n - 1 || j == 0 || j == n - 1)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
0 Response to "Diagonal & Sides of a Rectangle"
Post a Comment