Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C programming: Program Setup Your program should ask the user to enter the numbe

ID: 3790527 • Letter: C

Question

C programming:

Program Setup

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.

Sample Run:

(Here are two examples of what your program should look like when its finished).

Run 1:

How many rows for your star design?

5

How many stars on the first row?

8

* * * * * * * *

* * * * * * *

* * * * * * * *

* * * * * * *

* * * * * * * *

---

Run 2:

How many rows for your star design?

2

How many stars on the first row?

17

* * * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * *

Explanation / Answer

PROGRAM

#include<stdio.h>
#include<conio.h>
void main()
{
   int rows,stars,i,j;
   clrscr();
   printf("How many rows for your star design? ");
   scanf("%d",&rows);
   printf("How many stars on the first row? ");
   scanf("%d",&stars);
   for(i=1;i<=rows;i++)
   {
       if (i % 2 == 0)
       {
           for(j=1;j<stars;j++)
           {
               printf("*");

           }
           printf(" ");
       }
       else
       {
           for(j=1;j<=stars;j++)
           {
               printf("*");
           }
           printf(" ");
       }
   }
   getch();
}

SAMPLE OUTPUT

How many rows for your star deisng?

3

How many stars on the first row?

2

**

*

**