Can you write a c program for the following output?
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