Breaking

Wednesday, 2 March 2016

c++ Lecture 15 In Urdu

   nested for loop
 
 

1
1  2 
1  2  3 
1  2  3  4
1  2  3  4  5

#include<iostream.h>
#include<conio.h>
void main()
{
int a , b;
for(a=1;a<=5;a++)
{
  for(b=1;b<=a;b++)
{
  cout<<b<<”    “;
}
  cout<<endl;

}
getch();
}

·        Es me ham ne 2 int type k varible liye jes ko a and b name assign kia.
·        Per outer loop logaya a k lay a for line.
·        Outer k ander inner loop lagya b for print
·        Ok pehly outer loop chaly ga
·        a ko 1 se initialize kai
·        conidtion check ho ge a<=5 yas q k a=1 hai condition true hai
·        a me increment ho jay ga
·        body me aye ga inner loop ho ge
·        b ko 1 se initailize kia
·        condition check ho ge b<=a ho to equal hai q k abi a ke value 1 hai true hai b me increment ho k body me aye ga
·        cout<<b<<”   “; means k 1 print ho ga b ke value 1 ha
·        line change ho jay ga per body 
·        ab b ke value 2 ho gai condition check ho ge b<=a false ho ga q k a ke value 1 hai ur b ke 2 ho ge next statement chali ge
·        oper jay ga outer py a ke value 2 ho gai
·        condtion check ho ge 2 <=5 true hai body me aye ga
·        inner loop check ho ge b ke value 1 hai a se less hai condition true  hai increment ho k cout ke staement chali ge 1 print ho ga q k abi b ke value 1 k lay check ho gai te
·        ab b k value 2 ho gai hai condition check ho ge b<=a true hai q k 2<=2 equal hai 2 print ho ga 
·        per b me increment ho k check ho ge false ho jai ge q k a ke value ab 2 hai
·        next staement chali ge endl wali line change ho jai ge
·        outer py jay ga a me increment ho gai 3 ho jay ga
·        inner py aye ga b ke value 1 hai conditon check ho ge b<=a yas q k b 1 hai ur a 3 hai body me aye ga
·        1 print ho jay space aye ga per incremnt ho k conndtion check ho ge 2<=3 yas 2 print ho ga
·        Per incremnt ho k condition check ho ge 3<=3 true equal hai es lay 3 print ho ga increment ho k conndtion check ho ge false ho jay ga qk 4<=3 body se bahr aye ga
·        Line change ho jai ge outer py jay ga
·        A 4 hojay ga ondition check ho ge 4<=5 true hai body me aye ga
·        Inner chali ge es tarha hota rahy ga
  


12345
1234
123
12
1


#include <iostream>
#include<iostream.h>
 Void mian()
{
           int N = 5;
           int M = N;
           for (int i = 0; i < N; i++)
           {
                       for (int j = 1; j <= M; j++)
                       {
                                   cout << j;
                       }
                       cout << endl;
                       M--;
           }
           getch();
}

·        Es me ham ne n ko initilize kia 5 se
·        Ur m ko equal kia n k jab n 0 ho jay ga to m already 0 ho jay ga
·        Per outer loop lgya I ko 1 se initial… kia condition check ke k I liss hai ya equal hai n k to less hai q k n 5 hai ur I 1
·        Inner py aya inner loop me hm ne j varible lia ur 1 se initial… kia
·        Per check kia k j<=m to less hai q k m 5 hai ur j 1 body me aya
·        1 print ho gea increment ho k j 2 ho gea condtion check ho gai 2<=m true hai q k m 5 hai increment ho gai
·        Body me aya 2 k lay abi ok print ho gea 2
·        Per ab 3 ho gea check ho ga 3<=m true hai increment ho gea
·        Body me aya 3 print ho gea
·        Per condition check ho ge 4<=m true hai increment ho k body me aya
·        4 print ho gea
·        Per condition check ho ge 4<=m true hai incrment ho k body me aya 4 print ho gea
·        Per condition check ho ge 5<=m true hai q k equal hai increment ho k body me aya
·        5 print ho ga per condition check ho ge false ho jay ga q 6<=5 false hai inner se bahr aya ur pehli line me ye print hoa
·        12345
·        Next statement cout<<endl; line change ho ge
·        Next statement m—to m 4 ho jay ga
·        Per inner py jay ga
·        Ab I ke value 2 hai condition check ho ge 2<=5 less hai true hai inbcrement ho k body me aya ga body me inner loop hai
·        Inner loop check ho ge j=1 condtion check ho ge 1<=m to ab m ke value 4 hai true hai increment ho ga 
·        Body me ya ga 1 k lay body chali ge  1 print ho ga
·        Per condition check ho ga 2<=4 true hai incremnet ho k body 2 k lay chali ge
·        2 print ho ga es traha hota rahy ga
Ur jab outer loop false ho jay to program terminate ho jay ga
#include <iostream>
#include<conio.h>
void main()
{
for(int i = 0;  i < 3; i++)
   {
     int j = 0;
      for(int j = 0;  j < 5; j++)
   {
      cout << "i = " << i << " and j = " << j << endl;          
   }      
    }
getch();
}

i = 0 and j = 0
i = 0 and j = 1
i = 0 and j = 2
i = 0 and j = 3
i = 0 and j = 4
i = 1 and j = 0
i = 1 and j = 1
i = 1 and j = 2
i = 1 and j = 3
i = 1 and j = 4
i = 2 and j = 0
i = 2 and j = 1
i = 2 and j = 2
i = 2 and j = 3
i = 2 and j = 4

hope k sab ko samj aya ho ga ab

Reg:: Mt Ali okz 

No comments:

Post a Comment