Tuesday, 31 December 2013

C++ program which reads a lowercase letter and print equivalent uppercase letter

#include<iostream.h>
void main()
{

  clrscr();
  char s1,s2;
  cout<<"Enter The lower case charecter\n";
  cin>>s1;
  s2=s1-32;
  cout<<"\n upper case letter of " <<s1<<" is "<<s2;
   getch();
}

Example of Local Variable Using C++

1st example:::::::---------
#include<iostream.h>
  void function1()
 {
  int x;  
  x=10;
  cout<<"\n" <<x;
 }
void function2()
{
int x=34;
cout<<"\n" <<x;
}
void main()
{
       clrscr();
       function1();
       function2();

}

2nd example:::::::---------
#include<iostream.h>
void main()
{
   clrscr();
   int x =10        
   if(x==10)
    {
         int x; /*this x hides outer x*/
         x=77;
        cout<<"Inner x : " <<x;
     }
  cout<<"\n Outer x : "  <<x;
}

C++ Program prints the number 10 ten times Using static variable

#include<iostream.h>
void function()
{
static int k=10;
 cout<<k<<endl ;
 k++;
}
void main()
{
      clrscr();
     int i=10;
     for(i=0;i<10;i++)
     {
       function();
     }
}

C++ program to differentiate Local variable

#include<iostream.h>
void function()
{
  int j=10;
  cout<<j<<"\n" ;
  j++;
}
void main()
{
       clrscr();
     int i=10;
     for(i=0;i<10;i++)
     {
       function();
     }
}

Global Variable Example Using C++

#include<iostream.h>
int count;                               /* count is global*/
void function1();
void main()
{
 clrscr();

  count=100;

   function1();

   getch();

}
void function1()
{
   int temp;
   temp=count;
   cout<<"\n the value of temp and count ::" <<temp<<" " <<count;

}

C++ Program To Print The Perfect Square Number Which is Less Than 1000

#include<iostream.h>
void main()
{
   clrscr();
   int n=1000, s=0;
   cout<<"The Squre values Which is less Than 1000 is::  " ;

   for(int i=1;s<n;i++)
    {
      s=i*i;
      if(s>n)
      break;

     cout<<s<<" ";

    }


       getch();

}

C++ program to finding the maximum element in an array

#include<conio.h>
#include<iostream.h>
#include<stdio.h>
void main()
{
      clrscr();

    int array[]={1,2,3,4,5};

  int var1=array[0];
  for(int i=1;i<=5;i++)
   {  if(var1<array[i])
       var1=array[i];
   }
  cout<<var1;
       getch();

}