CrazyEngineers
  • c++ problem

    Ammar Aziz

    Ammar Aziz

    @ammar-aziz-7MLZYl
    Updated: Oct 23, 2024
    Views: 1.1K
    Dear friends is any one of you explain me about nested loops in c++ with examples
    also please tell me about a c++ program which displays a pyramid made of *(sterics)
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Varsha0802

    MemberMay 9, 2011

    Nested loops are loops which run inside other loops.

    Program for displaying a pyramid:
    #include<stdio.h>
    int main()
    { int i,j,k;
    for(i=1;i<=5;i++)
    { for(k=5;k>=i;k--)
    printf(" ");
    for(j=2;j<=2*i;j=j+1)
    { printf("*");
    }
    printf("\n");
    }
    return(0);
    }
    Here, two loops are running inside a for loop. Therefore, the loops are nested.
    Are you sure? This action cannot be undone.
    Cancel
  • PraveenKumar Purushothaman

    MemberMay 9, 2011

    @Varsha, it would be better to write the coding inside the code tags...
    #include<stdio.h>
    int main()
    {
      int i,j,k;
      for(i=1;i<=5;i++)
      {
        for(k=5;k>=i;k--)
          printf(" ");
        for(j=2;j<=2*i;j=j+1)
          printf("*");
        printf("\n");
      }
      return(0);
    }
    Are you sure? This action cannot be undone.
    Cancel
  • Varsha0802

    MemberMay 10, 2011

    praveenscience
    @Varsha, it would be better to write the coding inside the code tags...
    #include<stdio.h>
    int main()
    {
      int i,j,k;
      for(i=1;i<=5;i++)
      {
        for(k=5;k>=i;k--)
          printf(" ");
        for(j=2;j<=2*i;j=j+1)
          printf("*");
        printf("\n");
      }
      return(0);
    }
    Ok i'll keep it in mind from the next time. Thanks for pointing in out.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register