Code: /* * * * * * * * * * */ #include <stdio.h> void displayStar() { int starCount = 0; bool invalid = true; while(invalid) { printf("Enter odd number of start you wants in row/column -> "); scanf("%d", &starCount); if((starCount % 2 == 0) || (starCount > 100) || (starCount <= 0) ) { printf("Please Enter any ODD number in range of 3 to 100\n"); invalid = true; fflush(stdin); } else{ invalid = false; } } int innerCount = 0; int outerCount = 0; for(outerCount = 0; outerCount < starCount; outerCount++) { for(innerCount = 0; innerCount < starCount; innerCount++) { if((innerCount == outerCount) || (innerCount == starCount - outerCount -1)) { printf("*"); } else { printf(" "); } } printf("\n"); } } int main(int argc, char* argv[]) { displayStar(); return 0; }
Code: /* * * * * * * * * * */ #include <stdio.h> void displayStar() { int starCount = 0; bool invalid = true; while(invalid) { printf("Enter odd number of start you wants in row/column -> "); scanf("%d", &starCount); if((starCount % 2 == 0) || (starCount > 100) || (starCount <= 0) ) { printf("Please Enter any ODD number in range of 3 to 100\n"); invalid = true; fflush(stdin); } else{ invalid = false; } } int innerCount = 0; int outerCount = 0; for(outerCount = 0; outerCount < starCount; outerCount++) { for(innerCount = 0; innerCount < starCount; innerCount++) { if((innerCount == outerCount) || (innerCount == starCount - outerCount -1)) { printf(" * "); } else { printf(""); } } printf("\n"); } } int main(int argc, char* argv[]) { displayStar(); return 0; }