Problem 4: Diamond

Write a program to print the following output:
                           *
                        * * *
                     * * * * *
                  * * * * * * *
               * * * * * * * * *
                  * * * * * * *
                     * * * * *
                        * * *
                           *

5,689 total views, 10 views today

Comments

comments

14 thoughts on “Problem 4: Diamond”

  1. #include

    int main()
    {
    int n, c, k, empty = 1;

    printf(“RoW numbers:”);
    scanf(“%d”, &n);

    empty= n – 1;

    for (k = 1; k <= n; k++)
    {
    for (c = 1; c <= empty; c++)
    printf(" ");

    empty–;

    for (c = 1; c <= 2*k-1; c++)
    printf("*");

    printf("\n");
    }

    empty = 1;

    for (k = 1; k <= n – 1; k++)
    {
    for (c = 1; c <= empty; c++)
    printf(" ");

    empty++;

    for (c = 1 ; c <= 2*(n-k)-1; c++)
    printf("*");

    printf("\n");
    system ("color 4A");
    }

    printf("Thank you sir For the great job\n\n\n\n");
    return 0;
    }

  2. #include
    int main (){
    printf(” *\n ***\n *****\n *******\n*********\n *******\n *****\n ***\n *”);

    return 0;
    }

  3. #include
    main()
    {
    printf(“\t\t\n * “);
    printf(“\t\t\n *** “);
    printf(“\t\t\n ***** “);
    printf(“\t\t\n ******* “);
    printf(“\t\t\n *********”);
    printf(“\t\t\n ******* “);
    printf(“\t\t\n ***** “);
    printf(“\t\t\n *** “);
    printf(“\t\t\n * “);

    }

  4. #include
    int main()
    {
    int n,c,k,space=1;
    printf(“Enter the number of rows\n”);
    scanf(“%d”,&n);
    space=n-1;
    for(k=1;k<=n;k++)
    {
    for(c=1;c<=space;c++)
    printf(" ");
    space–;
    for(c=1;c<=2*k-1;c++)
    printf("*");
    printf("\n");
    }
    space=1;
    for(k=1;k<=n-1;k++)
    {
    for(c=1;c<=space;c++);
    printf(" ");
    space++;
    for(c=1;c<=2*(n-k)-1;c++)
    printf("*");
    printf("\n");

    }
    }

  5. #include
    int main (){
    printf(” *\n ***\n *****\n *******\n*********\n *******\n *****\n ***\n *”);

    return 0;
    }

  6. #include
    int main()
    {
    printf(“\t *\n\t ***\n\t *****\n\t *******\n\t*********\n\t *******\n\t *****\n\t ***\n\t *”);
    return 0;
    }

  7. #include
    int main (){
    printf(” *\n ***\n *****\n *******\n*********\n *******\n *****\n ***\n *”);

    return 0;
    }

  8. #include
    int main()
    {
    printf(” *\n”);
    printf(” ***\n”);
    printf(” *****\n”);
    printf(” *******\n”);
    printf(“*********\n”);
    printf(” *******\n”);
    printf(” *****\n”);
    printf(” ***\n”);
    printf(” *\n”);

    return 0;
    }

  9. #include
    int main (){
    printf(” *\n ***\n *****\n *******\n *********\n *******\n *****\n ***\n *”);

    return 0;
    }

  10. #include
    int main()
    {
    printf(“\t\t\n * “);
    printf(“\t\t\n *** “);
    printf(“\t\t\n ***** “);
    printf(“\t\t\n ******* “);
    printf(“\t\t\n*********”);
    printf(“\t\t\n ******* “);
    printf(“\t\t\n ***** “);
    printf(“\t\t\n *** “);
    printf(“\t\t\n * “);
    return 0;

    }

  11. #include
    int main()
    {
    printf(“4space*\n 3space***\n 2space*****\n 1space*******\n no space*********\n 1space*******\n 2space*****\n 3space***\n 1space*”);

    return 0;
    }

  12. #include
    int main()
    {
    printf(“4space*78space***76space*****74space*******72space*********72space*******74space*****76space***78space**”);
    return 0;
    }

  13. #include
    int main()
    {
    printf(” *\n ***\n *****\n *******\n*********\n *******\n *****\n ***\n *”);

    return 0;
    }

Leave a Reply

Your email address will not be published.