Question: C PROGRAMMING Your roommates have embarked on a project to paint the common room in a manner similar to the stripes on the US flag.
C PROGRAMMING
Your roommates have embarked on a project to paint the common room in a manner similar to the stripes on the US flag. For example, if they want 5 rows with the first row with 8 stars, their design would look like the following:
* * * * * * * *
* * * * * * *
* * * * * * * *
* * * * * * *
* * * * * * * *
You've decided to build a program that will print this design to a file for your roommates to see. Your program should ask the user to enter the number of rows and the number of stars in the first row. The even numbered rows should have one fewer star than the odd numbered rows. Then, construct your program to print the star design. This program will always print to output.txt.
Fill in the following program so that it will print your roommates pattern to the file called output.txt. WHERE IT SAYS "[SELECT]" , PLEASE SELECT THE CORRECT ANSWER. ANSWER CHOICES ARE IN BOLD
#include
int main() {
int rows, stars, i, j; [ Select ] ["FILE", "FILE ofp", "FILE *ofp", "FILE *FILE", "FILE.h", "FILE pointer ofp"] = [ Select] ["fopen("output.txt", "w")", "fopen("output.txt", "r")", "fopen(output.txt, "w")", "fopen("output.txt", w)", "fopen(output.txt, w)", "fileopen("output.txt", "w")"] ;
printf("How many rows for your star design? "); scanf("%d", &rows);
printf("How many stars on the first row? "); scanf("%d", &stars);
for(i=0; [ Select ] ["i <= rows", "i < rows", "i > rows", "i >= rows", "i == rows", "i != rows"] ; i++) {
if (i%2 == 0) {
for( [ Select ] ["j = 1", "j = 0", "j = i", "j = i % 2", "j = rows", "j = cols"] ; j [ Select ] ["printf", "fprintf", "scanf", "fscanf", "filewrite", "fileprint"] (ofp, "* "); } else { for(j=0; [ Select ] ["j < stars", "j <= stars", "j < stars -1", "j > stars", "j < stars + 1", "j == stars"] ; j++) fprintf(ofp, " *"); } fprintf( [ Select ] ["ofp", "*ofp", "FILE *ofp", "ifp", "*ifp"] , " "); } fclose( [ Select ] ["ofp", "*ofp", "output.txt", ""output.txt""] ); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
