Thursday, 13 February 2014

write a program to print rhombus


/* write a program to print rhombus                       * 
                                                                              *     *
                                                                            *    *   *
                                                                              *     *            
                                                                                  *
#include<stdio.h>
main()
{
int n,i,j;
printf("enter the number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
printf(" ");  //loop for spaces
}
for(j=1;j<=i;j++)
{
printf("* ");    //after star there is a single space required
}
printf("\n");
}
for(i=1;i<n;i++)
{
for(j=1;j<=i;j++)
{
printf(" ");
}
for(j=1;j<=n-i;j++)
{
printf("* ");   //after star there is a single space required
}
printf("\n");
}
}


//program is tested on gcc compiler

No comments:

Contact Form

Name

Email *

Message *