#3 Diagonal & Sides of a Rhombus/Diamond
Input: 9 (input should be an odd number only, else the desired output will not be obtained)
Output:
Diagonal & Sides of a Rhombus/Diamond :
#include <stdio.h>
int main()
{
int i, j, n;
printf("Enter Number : ");
scanf("%d", &n); // ‘n’ must be odd
int num1 = n / 2 * 3;
for(i = 0; i < n; i++)
{
for(j = 0; j < n; j++)
{
// center horizontal, center vertical, upper left diagonal, bottom left diagonal, upper right diagonal, bottom right diagonal
if(i == n / 2 || j == n / 2 || i + j == n / 2 || i - j == n / 2 || j - i == n / 2 || i + j == num1)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
0 Response to "Diagonal & Sides of a Rhombus/Diamond"
Post a Comment