Diamond.C |
---|
#include int main() { int n, inner, outer, space = 1; printf("Enter a number\n"); scanf("%d", &n); space = n - 1; for (outer = 1; outer <= n; outer++) { for (inner = 1; inner <= space; inner++) printf(" "); space--; for (inner = 1; inner <= 2*outer-1; inner++) printf("*"); printf("\n"); } space = 1; for (outer = 1; outer <= n- 1; outer++) { for (inner = 1; inner <= space; inner++) printf(" "); space++; for (inner = 1 ; inner <= 2*(n-outer)-1; inner++) printf("*"); printf("\n"); } return 0; } |
Thursday, August 3, 2017
Making a Diamond Aski Art in C
This is the expected final output. User will enter a number n where n is the position of the middle column asterisk. This exercise requires multiple nested loops
The Code diamond's number of rows is n/2-1to make n's value to be the middle row.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment