Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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,

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.

#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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions