Breaking

Wednesday, 2 March 2016

C++ Lecture 12 In Urdu

          Do-while loop practice
                in do-while loop first execute body than check condition……
                     
           Syantx 
                         do
               {
                  statement 1;
                   statement 2;
                                      ..
                                      …
                     }while(condition);
                     
                     factorial programm using do-while….                                                                                                                                                                                                                                                                   
                #include<iostream.h>
                    #include<conio.h>
                  void main()  
                {
              clrscr();
                  int f,m,n;
                cout<<”Enter any number..”;
                     cin>>n;
                          m=n;
                        f=1;
                         do
                          {
                              f=f*n;
                                 n--;
                                           
                                 }while(n>=1);
                           cout<<”factorial of”<<m<<”=”<<f;
                             getch();
                                }


Revise All …

·        #include<iostream.h> is a header file of input and output…
·        #include<conio.h> is a header file use for getch()
·        Getch use for print screen
·        Cout use for output …
cin use for input
clrscr use for clear the print screen
·        Endl use for line change
·        Ok ab program par aty hai
·        Es me ham ne 3 varible liye int tye k jes ko ko f,m,n assign kia
·        F use for factorial
·        n user input ly ga js ka wo factorial lina chahta hai
·        ur jo value ham n k lay lain gy usr se wo m me save ho jai ge ur f ko 1 vale de
·        es k bad do ke body chali ge farz kary k usr input me n ko 5 value de hai
·        f=f*n means k   1*5 ye f me add ho jai ge
·        next statemenr n—decremnt ho ge 5 se 4 ho jai ge
·        condition check ho ge n>=1 ha q k n ke value abi 4 hai
·        do me jai ge
·        5=5*4  means 20 f ke value 20 ho jai
·        N me decrement ho 3 ho jay ga
·        Es tarha tarha jab tak contion false n ho hota rahy ga
·        Ur jab condition false ho jay to output aye ge
Factorial of 5 = kuch b ata ho wo ajy ga

#include<iostream>
#include<conio.h>
Void main()
{
     int a;
     cout<<"Enter the Number :";
     cin>>a;
       int c= 1;
     do
     {
         cout<<"Execute Do While "<<c<<" time"<<endl;
         c++;
     }while (c<= a);
     getch();
}

·        Es me ham ne int type ka varible liye kes ko ham ne a ka nam assign kia
·        Per user se input le for a faraz kary user ne 3 dia
·        Ek ur variable liye c jo ko 1 se initialze kai
·        Es k bad do ke body execute ho ge
·        cout<<"Execute Do While "<<c<<" time"<<endl; ye statemen chali ge
·        first time result aye ga Execute do while 1 time line change ho e
·        c me increment ho ge 2 ho jay ga
·        condition check ho ge true hai q k 2 less hai 3 se
·        do ke body than execute ho ge
Execute do while 2 time
·        c me increment ho ge  3 ho jai ge
·        condition check ho ge true ho ge q k 3 equal hai 3 k
do ke body execute ho ge
·        Execute do while 3 time
·        C me increment ho jay ge 4 ho ga
·        Condition check ho ge false ho jay ur output aji ge

Enter the Number :3
Execute Do While 1 time
Execute Do While 2 time
Execute Do While 3 time





#include <iostream>
#include<conio.h>
void main()
{
    float n, sum = 0.0;
   
    do {
        cout<<"Enter a number: ";
        cin>>n;
        sum += n;   //sum=sum+n;
    }
    while(n != 0.0);
    cout<<"Total sum = "<<sum;
    getch();
}

·        Es me jab tak usr 0 nahe dy ga input me tab tak es me addition ho ge
·        Farz kary pehly me user 4.5 dy to ye sum me add ho jay ga
·        Condtion chewck ho user ne 0 to nahe dia to nahe per input ly ga es tarha jab user 0.0 dy ga to sab add ho k sum me show ho jain g
Enter a number: 4.5
Enter a number: 2.34
Enter a number: 5.63
Enter a number: 0
Total sum =12.47

I hope k ap sab ko do while ke samj aye ho ge and InshAllah Ap sab ab khud se programm bana sakty ho

Reg:Mt Ali Okz

No comments:

Post a Comment