C language Nested loop Example
Example 1: 
👇 आकृति प्रिंट करवाना
          *
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
    #include <stdio.h>
    #include <conio.h>
    void main()
    {
        int a, b;
        printf("\n\n\tnested loop for print '*' X 10 \n\n");        
        for (a = 1; a <= 10; a++)
        {
            for (b = 1; b <= a; b++)
            {
                printf(" * ");
            }
            printf("\n");
        }
        getch();
    }
Output:- 
                  nested loop for print '*' X 10
 *
  *  *
  *  *  *
        *  *  *  *
     *  *  *  *  *
  *  *  *  *  *  *
 *  *  *  *  *  *  *
 *  *  *  *  *  *  *  *
 *  *  *  *  *  *  *  *  *
 *  *  *  *  *  *  *  *  *  *
Example 2:-
 User से Row का इनपुट लेकर दो आकृति 👇 एक साथ प्रिंट करवाना:-
*  *  *  *  *
*  *  *  *  *
*  *  *  *  *
*  *  *  *  *
*  *  *  *  *
 *
 *
 *  *
 *  *  *
 *  *  *  *
 *  *  *  *  *
    #include <stdio.h>
    #include <conio.h>
    void main()
    {
        int num, i, j;
        printf("\n\n\tprint '*' \n\t Enter a Number : ");
        scanf("%d", &num);
        printf("\n\npress any key....");
        getch();
        printf("\n\t  %d X %d\n\n", num, num);
        for (i = 1; i <= num; i++)
        {
            for (j = 1; j <= num; j++)
            {
                printf(" * ");
            }
            printf("\n");
        }
        printf("\n\n\tnow we print ract angle\n\t press any key..... ");
        getch();
        printf("\n\n");
        for (i = 1; i <= num; i++)
        {
            for (j = 1; j <= i; j++)
            {
                printf(" * ");
            }
            printf("\n");
        }
        getch();
    }
Output:-
        print '*'         
         Enter a Number : 6
press any key....
          6 X 6
 *  *  *  *  *  * 
 *  *  *  *  *  *
 *  *  *  *  *  *
 *  *  *  *  *  *
 *  *  *  *  *  *
 *  *  *  *  *  *
        now we print ract angle
         press any key.....
 * 
 *  *
 *  *  *
 *  *  *  *
 *  *  *  *  *
 *  *  *  *  *  *
Example 3 :-
User से Row का इनपुट लेकर आकृति 👇 प्रिंट करवाना:-
*   *   *   *   *
*   *   *   *
*   *   *
*   *
*
*
*   *
*   *   *
*   *   *   *
*   *   *   *   *
    #include <stdio.h>
    #include <conio.h>
    void main()
    {
        int i, j, num;
        printf("\n\n\t Enter a Number : ");             
        scanf("%d", &num);
        printf("\n\n");
        for (i = num; i >= 1; i--)
        {
            for (j = 1; j <= i; j++)
            {
                printf(" * ");
            }
            printf("\n");
        }
        for (i = 1; i <= num; i++)
        {
            for (j = 1; j <= i; j++)
            {
                printf(" * ");
            }
            printf("\n");
        }
        getch();
    }
Output:- 
         Enter a Number : 6
 *  *  *  *  *  * 
 *  *  *  *  *    
 *  *  *  *       
 *  *  * 
 *  *
 *
 *
 *  *
 *  *  *
 *  *  *  *
 *  *  *  *  *
 *  *  *  *  *  *
Example 4 :-
User से Row का इनपुट लेकर आकृति 👇 प्रिंट करवाना:-
                          *<>* 
 *<>*      *<>*
 *<>*      *<>*      *<>*
 *<>*      *<>*      *<>*      *<>*
 *<>*      *<>*      *<>*      *<>*      *<>*
  <*_*) (*_*>
  <*_*) (*_*>         <*_*) (*_*>
  <*_*) (*_*>         <*_*) (*_*>     <*_*) (*_*>
  <*_*) (*_*>         <*_*) (*_*>         <*_*) (*_*>         <*_*) (*_*>
  <*_*) (*_*>         <*_*) (*_*>         <*_*) (*_*>         <*_*) (*_*>         <*_*) (*_*>       
    #include <stdio.h>
    #include <conio.h>
    void main()
    {
        int i, j, num;
        printf("\n \n \t Enter a Number : ");
        scanf("%d", &num);
        for (i = 1; i <= num; i++)
        {
            for (j = 1; j <= num; j++)
            {
                if (j <= i)
                {
                    printf("*<>* ");
                }
                else
                {
                    printf("\t\t");
                }
            }
            printf("\n");
        }
        for (i = 1; i <= num; i++)
        {
            for (j = 1; j <= num; j++)
            {
                if (j >= i)
                {
                    printf("\t\t");
                }
                else
                {
                    printf("<*_*)(*_*> ");
                }
            }
            printf("\n");
        }
        getch();
    }
Output:-
                     Enter a Number : 5
*<>* 
*<>* *<>* 
*<>* *<>* *<>* 
*<>* *<>* *<>* *<>*      
*<>* *<>* *<>* *<>* *<>* 
 style="text-align: left;"><*_*)(*_*>
<*_*)(*_*>  <*_*)(*_*>
<*_*)(*_*>  <*_*)(*_*>  <*_*)(*_*>
<*_*)(*_*>  <*_*)(*_*>  <*_*)(*_*>  <*_*)(*_*>
Example 5:-
User से एक number का इनपुट लेकर आकृति 👇 प्रिंट करवाना:-
                                                   *
                  *  *
               *  *  *
            *  *  *  *
         *  *  *  *  *
      *  *  *  *  *  *
   *  *  *  *  *  *  *
*  *  *  *  *  *  *  *
  
    #include <iostream>
    #include <conio.h>
    using namespace std;
    int main()
    {
        int num, i, j;
        cout << "\n\n\tEnter a Number : ";
        cin >> num;
        for (i = 1; i <= num; i++)
        {
            for (j = 1; j <= num; j++)
            {
                if (i <= (num - j))
                {
                    cout << "   ";
                }
                else
                {
                    cout << " * ";
                }
            }
            cout << endl;
        }
        getch();
        return (0);
    }
Output:-
        Enter a Number : 8
                     *
                  *  *
               *  *  *
            *  *  *  *
         *  *  *  *  *
      *  *  *  *  *  *
   *  *  *  *  *  *  *
*  *  *  *  *  *  *  *
Example 6 :- 
पिरामिंड की आकृति 👇 प्रिंट करवाना:-
                                    *
                            *  *  *
                         *  *  *  *  *
                      *  *  *  *  *  *  *
                   *  *  *  *  *  *  *  *  *
                *  *  *  *  *  *  *  *  *  *  *
             *  *  *  *  *  *  *  *  *  *  *  *  *
          *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
       *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *       
    *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *    
 *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
           #include <iostream>
    #include <conio.h>
    using namespace std;
    int main()
    {
        int i, j;
        cout << "\n\n\tPress Any key....";
        getch();
        cout << "\n\n\twelcome back......\n\n";
        for (i = 1; i <= 11; i++)
        {
            for (j = 1; j <= 21; j++)
            {
                if (j >= 12 - i && j <= 10 + i)
                {
                    cout << " * ";
                }
                else
                {
                    cout << "   ";
                }
            }
            cout << "\n";
        }
        getch();
        return (0);
    }
Output:-
          Press Any key....          welcome back......
                               *
                            *  *  *
                         *  *  *  *  *
                      *  *  *  *  *  *  *
                   *  *  *  *  *  *  *  *  *
                *  *  *  *  *  *  *  *  *  *  *
             *  *  *  *  *  *  *  *  *  *  *  *  *
          *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
       *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *       
    *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *    
 *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
    
 
 
0 Comments