Monday 26 August 2013

Lecture 159

Lecture 159
//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
void display(char*);  // Prototype
main ()
{

  char name[]={"Shahid"};
  display(name);
  getch();
  return 0;
}
void display(char name[])
{
  cout<<"Your name is : ";
  int i=0;
  while(name[i] != '\0')    
  {
        cout<<name[i];
        i++;
  }     
}

Output:

Lecture 158

Lecture 158

//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
int f(int);  // Prototype
int g(int);
main ()
{
  int x,y,s=2;
  s*=3;
  y=f(s);
  x=g(s);
  cout<<"\n "<<s<<y<<x;
  getch();
  return 0;
}
int t=8;
int f(int a)
{
  a+=-5;
  t-=4;
  return a+t;
}
int g(int a)
{
  a=1;
  t+=a;
  return a+t;
}


Output:

Lecture 157

Lecture 157
//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
int i=0;
void Val();  // Prototype
main ()
{
  cout <<"\n Main's i : "<<i;     
  i++;
  Val();
  cout <<"\n Main's i : "<<i;     
  Val();
  getch();
  return 0;
}
void Val()
{
  i=100;
  cout <<"\n Val's i : "<<i;     
  i++;
}


Output:

Lecture 156

Lecture 156

//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
void Extern();  // Prototype
int x=21;
void display();  // Prototype
main ()
{
  int x=20;
  cout <<"\n Variable Local x : "<<x;     
  display();
  Extern();
  getch();
  return 0;
}
void Extern()
{
  cout <<"\n Variable Global : "<<x;  
  extern int x;
  x=23;
  cout <<"\n Variable external : "<<x;

}
void display()
{
  cout <<"\n Variable Global : "<<x;  
}

Output:

Lecture 155

Lecture 155

//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
void Register();
void increment();
void increment1();  // Prototype
main ()
{
  Register();
  increment();
  increment();
  increment1();
  increment1();
  getch();
  return 0;
}
void Register()
{
  register int i;
   for(i=1;i<6;i++)
       cout <<"\n Register i : "<<i;

}
void increment()
{
    auto int i=1;
    cout <<"\n increment in auto i : "<<i;
    i=i+1;  
}
void increment1()
{
    static int i=1;
    cout <<"\n increment in static i : "<<i;
    i=i+1;  
}


Output:

Lecture 154

Lecture 154
//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
void Auto();
void Auto1();// Prototype
main ()
{
  Auto();
  getch();
  return 0;
}
void Auto()
{
  auto int i,j;
  cout <<"\n  i : "<<i<<"  j : "<<j;
  Auto1();
}
void Auto1()
{
  auto int i=1;
   {
        cout <<"\n  i : "<<i;    
         auto int i=2;
        {
          cout <<"\n  i : "<<i;    
          auto int i=3;
            {
               cout <<"\n  i : "<<i;    
            }
        }
   }
}
Output:

Monday 19 August 2013

Lecture 153

Lecture 153

//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
void swapr(int*,int*);  // Prototype
main ()
{
  int a=10,b=20;
  cout <<"\n a =  "<<a<<" b =  "<<b;
  swapr(&a,&b);
  getch();
  return 0;
}
void swapr(int *a,int *b)
{

   int t;
   t=*a;
   *a=*b;
   *b=t;
   cout <<"\n a =  "<<*a<<" b =  "<<*b;
    
}


Output:

Lecture 152

Lecture 152


//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
void swapv(int,int);  // Prototype
main ()
{
  int a=10,b=20;
  swapv(a,b);
  cout <<"\n a =  "<<a<<" b =  "<<b;
  getch();
  return 0;
}
void swapv(int a,int b)
{

   int t;
   t=a;
   a=b;
   b=t;
   cout <<"\n a =  "<<a<<" b =  "<<b;
    
}


Output:

Lecture 151

Lecture 151

//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
int pow(int,int);
int pow1(int,int,int);  // Prototype
main ()
{
  int number = 0;
  int power = 0;
  // Getting the input from the user
  cout << " Please enter the number ";
  cin>> number;
  cout << " Please enter the power number ";
  cin>> power;
  cout << "\n The Power number is : "<<pow(number,power);
  getch();
  return 0;
}
int pow(int n,int p)
{
   int n1=n;
   return pow1(n,p,n1);
 
}
int pow1(int n,int p,int n1)// It is a loop(Recursive call)
{
    
     if(p==1)
        return n1;
       n1=n1*n;
       p = p-1;
    return pow1(n,p,n1);
 
}

Output:

Friday 16 August 2013

Lecture 150

Lecture 150


//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
void fun();  // Prototype    
main ()
{
   cout<<"It is return message. \n";
   fun();
   cout<<"\n --------------------------- \n";
   cout<<"It would return nothing : \n ";       
   void fun();
  getch();
  return 0;
}
void fun()
{
  cout<<"\n Hello ......... : ";    
}


Output:


Lecture 149

Lecture 149


//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
int fun();  // Prototype    
char fun1();
main ()
{
  cout<<"\tCharacter \n";
  cout<<fun1();
  cout<<"\n\tInteger \n";
  cout<<fun();
  getch();
  return 0;
}
int fun()
{
 char ch;
 cout<<"Enter any alphabet : ";    
 cin>>ch;
 if(ch>=65 && ch<=90)
   return ch;
 else
   return ch+32;  
}
char fun1()
{
 char ch;
 cout<<"Enter any alphabet : ";    
 cin>>ch;
 if(ch>=65 && ch<=90)
   return ch;
 else
   return ch+32;  
}


Output:

Lecture 148

Lecture 148

//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
void  italy();
void  brazil();
void  argentina();   // Prototype 
main ()
{
  cout<<"\n I am in main";
  italy();
  cout<<"\n I am back in main";
  getch();
  return 0;
}

void  italy()
{
  cout<<"\n I am in italy";
  brazil();
    cout<<"\n I am back in italy";
}
void  brazil()
{
  cout<<"\n I am in brazil";
  argentina();
  cout<<"\n I am back in brazil";
}
void  argentina()
{
  cout<<"\n I am in argentina";
  cout<<"\n __________________";
}


Output:

Lecture 147

Lecture 147

//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
void  italy();
void  brazil();
void  argentina();   // Prototype 
main ()
{
  cout<<"\n I am in main";
  italy();
  brazil();
  argentina();
  getch();
  return 0;
}

void  italy()
{
  cout<<"\n I am in italy";
}
void  brazil()
{
  cout<<"\n I am in brazil";
}
void  argentina()
{
  cout<<"\n I am in argentina";
}

Output:

Wednesday 14 August 2013

Lecture 146

Lecture 146

//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
int isEven(int);   // Prototype 
main ()
{
   int i ;
  // Getting the input from the user
  cout<< " Please enter the number " ;
  cin >> i ;
  cout<< " Zero is Even and One is odd \n" ;
  cout << " Even or Odd : " << isEven(i);

  getch();
  return 0;
}
int isEven(int n){  return n%2; }

Output:



Lecture 145

Lecture 145
//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
int pow(int,int);    // Prototype 
main ()
{
  int number = 0;
  int power = 0;
  // Getting the input from the user
  cout << " Please enter the number ";
  cin>> number;
  cout << " Please enter the power number ";
  cin>> power;
  cout << "\n The Power number is : "<<pow(number,power);
  getch();
  return 0;
}
int pow(int n,int p)
{
   int n1=n;
   while(p!=0)
   {
     p = p-1;
     if(p==0)
          break;
     n1=n1*n;
   }
   return n1;
  
}
Output:

Monday 12 August 2013

Lecture 144

                Lecture 144
//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
int fac(int);    // Prototype 
main ()
{
  int number = 0;
  // Getting the input from the user
  cout << " Please enter the number to calculate the factorial ";
  cin>> number;
  cout << "\n The factorial number is : "<<fac(number);
  getch();
  return 0;
}
int fac(int n)
{
   if(n==0) return 1;
   if(n>0)  return fac(n-1)*n;   

}
Output:

Sunday 11 August 2013

Lecture 143

                Lecture 143
//Procedures and Functions
//Code:
#include <iostream>
#include <conio.h>
using namespace std;
int square(int);    // Prototype 
main ()
{
  int result = 0;
  int number = 0;
  // Getting the input from the user
  cout << " Please enter the number to calculate the square ";
  cin>> number;
  result = square(number);
  cout << "\n The square number is : "<<  result;
  getch();
  return 0;
}
int square(int n)
{
   return n*n;   
}
Output: