Following C program will print diamond pattern for number n.
#include<stdio.h>
int main(){
int i, j, n=5;
for(i=0; i<n; i++)
{
for(j=0; j<n-1-i; j++)
printf(" ");
for(j=0; j<i; j++)
printf("* ");
printf("\n");
}
for(i=n-2; i>0; i--)
{
for(j=0; j<n-1-i; j++)
printf(" ");
for(j=0; j<i; j++)
printf("* ");
printf("\n");
}
return 0;
}
Output of program
*
* *
* * *
* * * *
* * *
* *
*
No comments:
Post a Comment