diff --git a/C/diamond.c b/C/diamond.c new file mode 100644 index 0000000..7987101 --- /dev/null +++ b/C/diamond.c @@ -0,0 +1,32 @@ +#include +int main() +{ + int n, c, k; + + printf("Enter number of rows\n"); + scanf("%d", &n); + + for (k = 1; k <= n; k++) + { + for (c = 1; c <= n-k; c++) + printf(" "); + + for (c = 1; c <= 2*k-1; c++) + printf("*"); + + printf("\n"); + } + + for (k = 1; k <= n - 1; k++) + { + for (c = 1; c <= k; c++) + printf(" "); + + for (c = 1 ; c <= 2*(n-k)-1; c++) + printf("*"); + + printf("\n"); + } + + return 0; +} \ No newline at end of file diff --git a/C/hollow_diamond.c b/C/hollow_diamond.c new file mode 100644 index 0000000..f6b8a30 --- /dev/null +++ b/C/hollow_diamond.c @@ -0,0 +1,50 @@ +// C Program To Print Hollow Diamond +#include +int main() +{ + + int n = 5, rows, columns; + for (rows = 1; rows <= n; rows++) { + + // used for printing the spaces + for (columns = n; columns > rows; columns--) { + printf(" "); + } + + // print star + printf("*"); + + // again print the spaces + for (columns = 1; columns < (rows - 1) * 2; + columns++) { + printf(" "); + } + if (rows == 1) { + printf("\n"); + } + else { + printf("*\n"); + } + } + for (rows = n - 1; rows >= 1; rows--) { + + // used for printing the spaces + for (columns = n; columns > rows; columns--) { + printf(" "); + } + + // print star + printf("*"); + for (columns = 1; columns < (rows - 1) * 2; + columns++) { + printf(" "); + } + if (rows == 1) { + printf("\n"); + } + else { + printf("*\n"); + } + } + return 0; +}