c++ problem

Ammar Aziz

Ammar Aziz

@ammar-aziz-7MLZYl Oct 23, 2024
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)

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Varsha0802

    Varsha0802

    @varsha0802-YohNRX May 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.
  • PraveenKumar Purushothaman

    PraveenKumar Purushothaman

    @praveenkumar-66Ze92 May 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);
    }
  • Varsha0802

    Varsha0802

    @varsha0802-YohNRX May 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.