Saturday 30 June 2012

Lecture: 106


                                                Lecture 106

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

  getch();
  return 0;
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Thursday 28 June 2012

Lecture: 105


                                                Lecture 105

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

  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Wednesday 27 June 2012

Lecture: 104


                                                Lecture 104

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

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Tuesday 26 June 2012

Lecture: 103


                                                Lecture 103


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

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Monday 25 June 2012

Lecture: 102



                                                Lecture 102

#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   char ch;
   int count=0; 
   cout<<"Type ina phrase : ";
   while((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 24 June 2012

Lecture: 101


                                                Lecture 101

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

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Saturday 23 June 2012

Lecture: 100


                                                Lecture 100

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

Compile the program Ctrl+F9

      Run program Ctrl+F10

Friday 22 June 2012

Lecture: 99


                                                Lecture 99

#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;
  i=1;
   while(i<=j)
     {
       F=F*i;
       i++;
     }
   cout<<"Factorial of "<<j<<" = "<<F;
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Thursday 21 June 2012

Lecture: 98


                                                Lecture 98
//Nested while 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; 
  row=1;
   while(row<22)//outer loop
   {
       col=1;
       while(col<40)//inner loop
       {
          COORD c;
          c.X=row; c.Y=col;
          SetConsoleCursorPosition(wHnd,c);
          cout<<"\xdb";     
          col++;
       }     
    cout<<endl;
    row++;
   }         
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Tuesday 19 June 2012

Lecture: 97


                                                Lecture 97

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

Compile the program Ctrl+F9

      Run program Ctrl+F10

Monday 18 June 2012

Lecture: 96


                                                Lecture 96


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

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Sunday 17 June 2012

Lecture: 95


                                                Lecture 95

// Loop while
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
    int n,a[5];
    cout<<"Initialisation array:\n ";
    n=0;
    while(n<5)
    {
         cout<<"Enter the number: ";
         cin>>a[n];
         n++;
    }
    cout<<"Print the array :\n";
    n=0;
    while(n<5)
    {
         cout<<a[n]<<endl;
         n++;
    }
    cout<<"Print the sort array :\n";
    int i,j,a1;
    i=0;
    while(i<5)
    {
       j=i;
       while(j<5)
       {
          if(a[i]>a[j])
          {
            a1=a[i];
            a[i]=a[j];
            a[j]=a1;
          }
          j++;
        }  
          i++;
       }
       n=0;
   while(n<5)
    {
         cout<<a[n]<<endl;
         n++;
    } 
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Saturday 16 June 2012

Lecture: 94


                                                Lecture 94

// Loop while
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
    int n,a[5];
    cout<<"Initialisation array:\n ";
    n=0;
    while(n<5)
    {
         cout<<"Enter the number: ";
         cin>>a[n];
         n++;
    }
    cout<<"Print the array :\n";
    n=0;
    while(n<5)
    {
         cout<<a[n]<<endl;
         n++;
    }
  getch();
  return 0;
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Wednesday 13 June 2012

Lecture: 93


                                                Lecture 93
// Loop While
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
    int n,a[5];
    cout<<"Initialisation array:\n ";
    n=0;
    while(n<5)
    {
         cout<<"Enter the number: ";
         cin>>a[n];
         n++;
    }
  getch();
  return 0;
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Sunday 10 June 2012

Lecture: 92


                                                Lecture 92

// Loop while
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
    int n,tnum,st,ed;
    cout<<"Enter the table number: ";
    cin>>tnum;
    cout<<"Enter the start table number: ";
    cin>>st;
    cout<<"Enter the end table number: ";
    cin>>ed;
    n=st;
    while(n<=ed)
    {
      cout<<"\n"<<tnum<<" X "<<n<<" = "<<tnum*n;
      n++;
    }
  getch();
  return 0;
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Saturday 9 June 2012

Lecture: 91


                                                Lecture 91

// Loop while
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
    int n,tnum;
    cout<<"Enter the table number: ";
    cin>>tnum;
    n=1;
    while(n<11)
    {
      cout<<"\n"<<tnum<<" X "<<n<<" = "<<tnum*n;
      n++;
    }
  getch();
  return 0;
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Thursday 7 June 2012

Lecture: 90


                                                Lecture 90

// Loop While
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
    int n;
    cout<<"Two table\n";
    n=1;
    while(n<11)
    {
      cout<<"\n2  X "<<n<<" = "<<2*n;
      n++;
    }
  getch();
  return 0;
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10