Print X Pattern Using For Loop In C Program
Program to print x pattern of n rows using for loop.
Example : pgm.c
#include<stdio.h> int main(){ int i,j,n; printf("\n Enter the limit:"); scanf("%d",&n); if(n%2==0){ n++; } for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if(j==i||j==n-i+1){ printf("* "); }else{ printf(" "); } } printf("\n"); } return 0; }
Output:
Enter the limit: 10
* * * * * * * * * * * * * * * * * * * * *