#include<stdio.h> int main() { int i,j,n=5; //for loop to print line 1 for(i=0; i<n;i++) { printf("* "); } printf("\n"); // logic for repeating line 2 to 4, n-2 times for(j=0; j<n-2; j++) { //for loop to print * * line 2 to 4 printf("* "); for(i=0; i<n-2; i++) printf(" "); printf("*\n"); } for(i=0; i<n;i++) { printf("* "); } return 0; } Output of the program * * * * * * * * * * * * * * * *
This programs will be useful to beginners of C language students.
ReplyDelete