Friday, November 4, 2016

গল্পটা প্রোগ্রামিং-এর (A tale of Programming): Tutorial 9- Making fun with looping

Code:

#include<stdio.h>
main()
{
    int n;
    printf("Enter no. of row n:");// standard n=10
    scanf("%d",&n);
/*1st part*/
 for(int i=0;i<n;i++)
    {
                for(int j=1;j<=n-i;j++)
        {
                    printf(" ");
        }

                 for(int j=n;j>=n-i;j--)
        {
                    printf("-");
        }
                         for(int j=n;j>=n-i;j--)
        {
                    printf(".");
        }
                        for(int j=1;j<=n-i;j++)
        {
                    printf(" ");
        }
                        for(int j=1;j<=n-i;j++)
        {
                    printf(" ");
        }

                 for(int j=n;j>=n-i;j--)
        {
                    printf("-");
        }
         for(int j=n;j>=n-i;j--)
        {
                    printf(".");
        }
                        for(int j=1;j<=n-i;j++)
        {
                    printf(" ");
        }
    printf("\n");
     }


/*2nd part*/
 for(int i=0;i<n;i++)
    {
               for(int j=n;j>=n-i;j--)
        {
                    printf(" ");
        }
                for(int j=1;j<=n-i;j++)
        {
                    printf(".");
        }

                        for(int j=1;j<=n-i;j++)
        {
                    printf("-");
        }
                         for(int j=n;j>=n-i;j--)
        {
                    printf(".");
        }

                     for(int j=n;j>=n-i;j--)
        {
                    printf("-");
        }
                            for(int j=1;j<=n-i;j++)
        {
                    printf(".");
        }
                    for(int j=1;j<=n-i;j++)
        {
                    printf("-");
        }

         for(int j=n;j>=n-i;j--)
        {
                    printf(" ");
        }

    printf("\n");
     }

/*1st part*/
 for(int i=0;i<n;i++)
    {
                for(int j=1;j<=n-i;j++)
        {
                    printf(" ");
        }

                 for(int j=n;j>=n-i;j--)
        {
                    printf("-");
        }
                         for(int j=n;j>=n-i;j--)
        {
                    printf(".");
        }
                        for(int j=1;j<=n-i;j++)
        {
                    printf("-");
        }
                        for(int j=1;j<=n-i;j++)
        {
                    printf(".");
        }

                 for(int j=n;j>=n-i;j--)
        {
                    printf("-");
        }
         for(int j=n;j>=n-i;j--)
        {
                    printf(".");
        }
                        for(int j=1;j<=n-i;j++)
        {
                    printf(" ");
        }
    printf("\n");
     }


/*2nd part*/
 for(int i=0;i<n;i++)
    {
               for(int j=n;j>=n-i;j--)
        {
                    printf(" ");
        }
                for(int j=1;j<=n-i;j++)
        {
                    printf(".");
        }

                        for(int j=1;j<=n-i;j++)
        {
                    printf("-");
        }
                         for(int j=n;j>=n-i;j--)
        {
                    printf(" ");
        }

                     for(int j=n;j>=n-i;j--)
        {
                    printf(" ");
        }
                            for(int j=1;j<=n-i;j++)
        {
                    printf(".");
        }
                    for(int j=1;j<=n-i;j++)
        {
                    printf("-");
        }

         for(int j=n;j>=n-i;j--)
        {
                    printf(" ");
        }

    printf("\n");
     }
}

Output:
Output of making fun with looping