Wednesday 30 May 2012

Lecture: 83


                                                Lecture 83
// While Loop
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
      int i;
      i=0;
      while(i<10)
      {
          cout<<i;    
          i++;
      }   
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Tuesday 29 May 2012

Lecture: 82


                                                Lecture 82

#include <iostream>
#include <conio.h>
#include <math.h>
double dPi;
using namespace std;
int main(void)
{
    dPi = 4.0 * tan(1.0);
     cout<<"Tan: "<<dPi; 
    dPi = 4.0 * cos(1.0);
     cout<<"\nCos: "<<dPi; 
    dPi = 4.0 * sin(1.0);
     cout<<"\nSin: "<<dPi; 
    dPi = 4.0 * log(1.0);
     cout<<"\nLog: "<<dPi; 
    dPi = 4.0 * atan(1.0);
     cout<<"\nInverse Tan : "<<dPi;   
    dPi = 4.0 * acos(1.0);
     cout<<"\nInverse Cos : "<<dPi;   
    dPi = 4.0 * asin(1.0);
     cout<<"\nInverse Sin : "<<dPi;   
     dPi =sqrt(4);   
     cout<<"\nSqrt : "<<dPi;   
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Monday 28 May 2012

Lecture: 81


                                                Lecture 81
//Print diagonal line in the screen
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
        int x,y,i,j;
        for(y=1;y<24;y++)
           {
              for(x=1;x<24;x++){
                 if(x==y)
                     cout<<"\xDB";
                 else if(x==2*y)
                     cout<<"\xB1";
                 else  
                     cout<<" ";
                 }   
                 for(i=1;i<3000;i++) //Timer loop                
                     for(j=1;j<7000;j++)                 
                        {}  
               cout<<endl;                      
           }

  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Sunday 27 May 2012

Lecture: 80


                                                Lecture 80

//Print diagonal line in the screen
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
        int x,y;
        for(y=1;y<24;y++)
           {
              for(x=1;x<24;x++)
                 if(x==y)
                     cout<<"\xDB";
                 else if(x==2*y)
                     cout<<"\xB1";
                 else   
                     cout<<" ";
               cout<<endl;                       
           }

  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Saturday 26 May 2012

Lecture: 79


                                                Lecture 79

//Print diagonal line in the screen
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
        int x,y;
        for(y=1;y<24;y++)
           {
              for(x=1;x<24;x++)
                 if(x==y)
                     cout<<"\xDB";
                 else if(x==24-y)
                     cout<<"\xDB";
                 else   
                     cout<<"\xB0";
               cout<<endl;                       
           }

  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Lecture: 78


                                                Lecture 78

//Print diagonal line in the screen
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
        int x,y;
        for(y=1;y<24;y++)
           {
              for(x=1;x<24;x++)
                 if(x==y)
                     cout<<"\xDB";
                 else
                     cout<<"\xB0";
               cout<<endl;                       
           }

  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Friday 25 May 2012

Lecture: 77


                                                Lecture 77

//Draws a checkerboard on the screen
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
        int x,y;
        for(y=1;y<9;y++)
           {
              for(x=1;x<9;x++)
                 if((x+y)%2==0)
                     cout<<"\xDB\xDB";
                 else
                     cout<<"  ";
               cout<<endl;                       
           }

  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Wednesday 23 May 2012

Lecture: 76


                                                Lecture 76

#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   int charcnt=0;
   int wordcnt=0;
   char ch;
   cout<<"Type in a phrase: \n";
   for(;(ch=getche()) != '\r';)
   {
       charcnt++;
       if(ch==' ')
              wordcnt++;
   }   
   cout<<"\nCharacter count is :"<<charcnt;
   cout<<"\nWord count is : "<<wordcnt;
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Tuesday 22 May 2012

Lecture 75


                                                Lecture 75

#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   char name[10]="Shahid";
   int i; 
   cout<<"Name:  ";
   for(i=0;name[i] != '\0';i++)
   {
       cout<<name[i];
   }   
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Monday 21 May 2012

Lecture: 74


                                                Lecture 74

#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   char ch;
   int count=0; 
   cout<<"Type ina phrase : \n";
   for(;(ch=getch()) != '\r';)
   {
       cout<<ch;
       count++;
   }   
    cout<<" \n\nCharacter count is : "<<count;
  getch();
  return 0;
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Sunday 20 May 2012

Lecture: 73


                                                Lecture 73

//Break for loop
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   int i; 
   for(i=1;i<10;i++)
   {
       if(i==5) break;         
    cout<<i<<" ";
   }        
  getch();
  return 0;
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Saturday 19 May 2012

Lecture: 72


                                                Lecture 72


//Nested for loop
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   int row,col; 
   for(row=1;row<3;row++)//outer loop
   {
       for(col=1;col<3;col++)//inner loop
            cout<<"Outer = " << row <<" Inner = "<<col<<endl;     
    cout<<endl;
   }        
  getch();
  return 0;
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Lecture: 71


                                                Lecture 71

#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
  system("CLS");//Clear screen
  int F=1,i=1,j;
  cout<<"Enter the factorial number: ";
  cin>>j;
   for(i=1;i<=j;i++)
       F=F*i;
   cout<<"Factorial of "<<j<<" = "<<F;
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Thursday 17 May 2012

Lecture: 70


                                                Lecture 70

//Nested for loop
#include <iostream>
#include <conio.h>
#include <windows.h>
HANDLE wHnd;
using namespace std;
 main ()
{  
  system("CLS");//Clear screen
  int row,col; 
   for(row=1;row<10;row++)//outer loop
   {   for(col=1;col<10;col++)//inner loop
       {
          COORD c;
          c.X=row; c.Y=col;
          SetConsoleCursorPosition(wHnd,c);
          cout<<"<Shahid>";     
       }   cout<<endl;
   }        
  getch();
  return 0;
}


Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Wednesday 16 May 2012

Lecture: 69


                                                Lecture 69
//Nested for loop
//fills square area on screen
#include <iostream>
#include <conio.h>
#include <windows.h>
HANDLE wHnd;
using namespace std;
 main ()
{  
  system("CLS");//Clear screen
  int row,col; 
   for(row=1;row<22;row++)//outer loop
   {
       for(col=1;col<40;col++)//inner loop
       {
          COORD c;
          c.X=row; c.Y=col;
          SetConsoleCursorPosition(wHnd,c);//gotoxy
          cout<<"\xdb";     
       }     
    cout<<endl;
   }        
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Tuesday 15 May 2012

Lecture: 68


                                                Lecture 68

//Nested for loop
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   int row,col; 
   for(row=1;row<13;row++)//outer loop
   {
       for(col=1;col<13;col++)//inner loop
             cout<<col*row<<"\xb3";     
    cout<<endl;
   }        
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Monday 14 May 2012

Lecture: 67


                                                Lecture 67

// Loop For
//Drawing a Graphics Character
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   int n; 
   char ch[5]="\xD9";
   for(n=1;n<40;n++)
        cout<<"\t"<<ch;
     
  getch();
  return 0;
}


Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10