Lecture-7 [Nested Loops with examples]

Lecture-7 [Nested Loops with examples]

Pattern 1


/*
*
**
***
****
*****
******
*******
********
*********
**********
*/

#include <iostream>
using namespace std;
int main()
{

    printf("Enter Number Of Row : ");
    int n;
    cin >> n;

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

        printf("\n");
    }

    return 0;
}


Pattern 2

  /* 
         *
        **
       ***
      ****
     *****
    ******
   *******
  ********
 *********
**********

*/



#include <iostream>
using namespace std;
int main()
{
    printf("Enter Number Of Row : ");
    int n;
    cin >> n;

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

        printf("\n");
    }

    return 0;
}


Pattern 3

/*
1
22
333
4444
55555
666666
7777777
88888888
999999999
*/


#include <iostream>
using namespace std;
int main()
{
    printf("Enter Number Of Row : ");
    int n;
    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            cout << i;
        }
        printf("\n");
    }
    return 0;
}




Pattern 4

/*
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55

*/


#include <iostream>
using namespace std;
int main()
{
    printf("Enter Number Of Row : ");
    int n;
    cin >> n;
    for (int i = 1, k = 1; i <= n; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            cout << k<< " ";
            k++;
        }
        printf("\n");
    }

    return 0;
}


Pattern 5

/*
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************

*/


#include <iostream>
using namespace std;
int main()
{
    printf("Enter Number Of Row : ");
    int n;
    cin >> n;

    for (int i = 1, k=0; i <= n; i++, k=0)
    {
        for (int j = 1; j <= n - i; j++)
        {
            printf(" ");
        }
        while (k != 2 * i - 1)
        {
            printf("*");
            k++;
        }
        printf("\n");
    }

    return 0;
}
Lecture-5.6 [All Loop]

Lecture-5.6 [All Loop]

ForLoop


1. ForLoop.cpp


#include <iostream>

using namespace std;
int main()
{
    for (int i = 0; i <= 100; i++)
    {
        cout << i;
        cout << " ";
        printf("I Love My Dreams\n");
    }

    return 0;
}


2. ForLoop2.cpp


#include <iostream>

using namespace std;

int main()
{
    int a, b;
    printf("How Much you want the number\n");
    cin >> a;
    printf("Which Number you want maltiplay\n");
    cin >> b;
    for (int i = 1; i <= a; i++)

        if ((i % b) == 0)
        {
            cout << " =  " << i << "\n";
        }

    return 0;
}



While Loop


1. WhileLoop.cpp


/*in the programing
    1 = true
    0 = false */

#include <iostream>
using namespace std;
int main()
{

    while (1)
    {
        printf("Helle Brother\n");
    }

    return 0;
}


2. WhileLoop_2.cpp

#include <iostream>
using namespace std;
int main()
{

    int a = 0;
    while (a < 10)
    {
        printf("Vikash\n");
        a++;
        //a++ increasing value 1 by 1 of a
    }

    return 0;
}


3. WhileLoop_3.cpp


#include <iostream>
using namespace std;

int main()
{
    int a;
   
    cin >> a;

    while (a > 5 && a < 10)
    {
        printf("Hello\n");
        a++;
    }
}


4. WhileLoop_4.cpp

#include <iostream>
using namespace std;
int main()
{
    int a;
    printf("Enter Your Number For  Loop\n");
    cin >> a;
    while (a < 10 || a > 5)             // in this program || = OR when we are using this it chack both any if it get any true it run the program
    {
        printf("Hello\n");
        a++;
    }
}


Continue Loop


1. Continue.cpp

#include <iostream>
using namespace std;
int main()
{

    for (int i = 0; i < 10; i++)
    {
        if (i == 5)
            continue;
        cout << i;
        printf("\n");
    }

    return 0;
}


Brack Loop


1. BrackLoop.cpp


#include <iostream>
using namespace std;

int main()
{
    for (int i = 0; i < 10; i++)
    {
        if (i == 5)
            break;
        cout << i << endl;
    }
    return 0;
}
Lecture-4 [Conditional Statements]

Lecture-4 [Conditional Statements]

1. if-else-if.cpp


#include <iostream>
using namespace std;

int main()
{
    int age = 18;
    printf("What is you age\n ");
    cin >> age;

    if (age < 18)
    {
        printf("gar par ja kar so ja ");
    }
    else
    {
        printf("welcome bro yoyo");
    }

    return 0;
}



2. if-else-if.cpp


#include <iostream>

using namespace std;

int main ()
{
    int age=10;
    printf("Bosdi vala chacha umar bta ?\n");
   
    cin>>age;
    if (age<18)
    {
        printf("Ja ka dud pi nu BC");
    }
    else if (age>18)
    {
        printf("enjoy tau...");
    }
    else
    {
        printf("tara bs bi na ha khuvarss lutna");
    }
   
    return 0;


}





3.  Switch.cpp


#include <iostream>
using namespace std;
int main()
{
    int age = 80;
    printf("choose a Number\n");
    printf("A. 10\n");
    printf("B. 20\n");
    printf("C. 30\n");
    printf("D. Nothing\n");

    cin >> age;

    switch (age)
    {
    case 10:
        cout << "Wronge age";
        break;
    case 20:
        cout << "Right age";
        break;
    case 30:
        cout << "Wrong age";
        break;
    default:
        cout << "Thank you BC";
    }
    return 0;
}






My Test


1. Option.cpp



#include <iostream>
using namespace std;

int main()
{

    char c, a, b, d;
    printf("Whos is PM of India ?\n");
    printf("A. Rajiv Modi\n"
           "B. Vikash SIngh\n"
           "C. Narandra Modi\n"
           "D. Tara Chacha\n");
    cin >> c;

    if (c = a)
    {
        printf("you answare is Wrong\n");
    }

    if (c = b)
    {
        printf("Answare Worng\n");
    }

    if (c = c)
    {
        printf("Your answare is Right\n");
    }

    if (c = d)
    {
        printf("chala ja bosdi ka\n");
    }

    return 0;
}




2.  Switch.cpp


#include <iostream>

using namespace std;

int main()
{
    int ans = 10;
    printf("\n \n \n \n \n \n ");
    printf("Choose one Right Number\n");
    printf(" 1. Ajay Singh Shekhawat\n 2. Vikash Singh Shekhawat\n 3. Ishu Singh Shekhawat\n 4. All");

    printf("\n \n");

    printf("Enter you nummber\n \n");

    cin >> ans;

    switch (ans)
    {
    case 1:
        printf("Oh Your Answare is Right");
        break;

    case 2:
        printf("Sorry Your Name is Wronge");
        break;

    case 3:
        printf("Sorry Your Name is Wronge");
        break;

    case 4:
        printf("Sorry Your Name is Wronge");
        break;

    default:
        break;
    }
    return 0;
}
Lecture-3 [user input and output

Lecture-3 [user input and output

#include <iostream>
using namespace std;
int main ()
{
    int a=12, b=10, z;
    float f=3.5;
    char c='A';
    double d=3.56789;
    cout<<a<<endl;
    cin>>a;
    z=a%b;
    cout<<a<<" "<<b<<" "<<f;
    return 0;
}




//Second Project Same  



#include <iostream>
using namespace std;
int main ()
{  
    int a, b, c;
    printf("Please Enter first Number\n");
    cin>>a;

    printf("Enter Second Number\n");
    cin>>b;

    printf("Your Sam is ");
   
    cout<<a+b;

   printf("\n");
    return 0;
}