Can you write a c program for the following output?
![**Sample Input and Output Explanation**
This section demonstrates how specific numeric inputs generate an output pattern using asterisks. Below is a detailed description of the samples:
---
**Sample Input**
- **Input 1:** 5
- **Input 2:** 6
---
**Sample Output**
1. For an input of **5**, the corresponding output is a symmetrical pattern of asterisks shaped like an hourglass:
```
*****
* *
*
* *
*****
```
2. For an input of **6**, the output is a symmetrical pattern of a larger hourglass with an additional row of asterisks:
```
******
* *
* *
*
* *
* *
******
```
---
**Explanation:**
- Each pattern starts and ends with a full row of asterisks matching the input number.
- The rows between are formed by placing spaces symmetrically, reducing the number of asterisks towards the center to form the hourglass shape.
- These patterns visually demonstrate symmetry and centered alignment relative to the given input number.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F11d0ce7c-4b0c-449a-baaa-6f40aee864fc%2Fc8640f80-c2c7-42d7-85f5-710b9d6704bc%2F5kkjs9s_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Program:
#include <stdio.h>
int main()
{
int number;
printf("Input:\n");
scanf("%d", &number); //reading number of rows or columns
printf("\nOutput:\n");
//loop to print pattern
for (int i = 1; i <= number; i++){
//for printing first and last row
if (i == 1 || i == number){
for (int j = 1; j <= number; j++)
printf("*");
}
//for printing all rows except first and last
else{
for (int j = 1; j <= number; j++){
if (j == 1 || j == number)
printf("*");
else
printf(" ");
}
}
printf("\n");
}
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)