facebook like button

03 May, 2011

program 41: Multiple Diamonds of $

The need:
     This is a simple program to print multiple diamonds of '$'. This program was is an extension of previous program.

The code: 
--------------------------------------------
#include<stdio.h>
main()
{
    int j,i,k,l,m,n;
    char c;
    do
    {
           printf("Enter the number of dollars in the base..");
        scanf("%d",&k);
        printf("\nEnter the number of diamonds you want ..");
        scanf("%d",&n);
        printf("\n\n");
        for (i=1;i<=k;i++)
        {
            for(m=1;m<=n;m++)
            {
                for(l=0;l<(k-i);l++)
                printf(" ");
                for (j=0;j<i;j++)
                printf ("$ ");
                for(l=0;l<(k-i);l++)
                printf(" ");
            }
            printf("\n");
        }
        for (i=1;i<=k;i++)
         {
            for(m=1;m<=n;m++)
            {
                printf(" ");
                for(l=1;l<i;l++)
                printf(" ");
                for (j=1;j<=k-i;j++)
                printf ("$ ");
                for(l=0;l<i;l++)
                printf(" ");
            }
            printf("\n");
          }
        printf("\nEnter y to try more...press any other key exit...\t");
        c=getchar();
        c=getchar();
        putchar('\n');
    }
    while(c=='y');
}
-------------------------------------------- 

The approach: 
This program creates multiple diamonds on the output screen. First it asks the user to input the number of stars in the base and the number of diamonds and then gives the output and asks the user whether he wants the program to stop or wants to draw one more diamonds. To understand functionality read program40.

No comments:

Post a Comment

feel free to ask your doubts... if any
you can post your doubts on
www.facebook.com/programsimply