Wednesday 18 December 2013

PROGRAM TO ADDITION TWO NUMBERS USING C++



#include<iostream.h>
#include<conio.h>
void main()
{
  clrscr();
  int a,b,sum;
  cout<<"enter  the value of number 1 and number 2";
  cin>>a>>b;
  sum=a+b;
  cout<<"\n"<<"sum of "<<" number 1 ="<<a<<" number  2="<<b<<”is”<<sum;
  getch();
}

Fibonacci Series up to 1 to 100 Using c++


#include<iostream.h>
#include<conio.h>
void main()
{
  int  n,i,fst=0,sec=1;
  cout<<" Fibonacci  Series up to 1 to 100";
  for(i=0;i<=100;i++)
  {
  if(i<=1)
  {
    n=i;
  }
  else
  {
    n= fst+sec;
   fst=sec;
   sec=n;
  }
Cout<<”\t”<<n;
}
  getch();
}

PROGRAM TO FIND LEAP YEAR USING C++


/*THIS PROGRAM CHECKS WHETHER THE
ENTERED YEAR IS LEAP OR NOT*/

#include<iostream.h>
#include<conio.h>
void main()
{
 int n;
 cout<<"enter the year";
 cin>>n;
 if(n%4==0)
 {
  cout<<"entered year is leap year";
 }
 else
 {
  cout<<"the entered year is not leap year";
 }
 getch();
}

TWO NUMBERS INTERCHANGE WITHOUT USING THE THIRD VARIABLE IN C++


#include<iostream.h>
#include<conio.h>
void main()
{
  clrscr();
  int a,b;
  cout<<"enter  the value of number 1 =”;
  cin>>a;
  cout<<"enter  the value of number 2";
  cin>>b;
  a=a+b;
  b=a-b;
  a=a-b;
 
  cout<<"\n"<<"after interchanging value of"<<" number 1 ="<<a<<"\n"<<" number  2="<<b;
  getch();
}
/*THIS PROGRAM ACCEPT TWO NUMBERS AS INPUT AND GENERATE TWO NUMBER IN OUTPUT BY     SWAPPING THEIR VALUES*/

TWO NUMBERS INTERCHANGE WITHOUT USING THE THIRD VARIABLE IN C++

#include<iostream.h>
#include<conio.h>
void main()
{
  clrscr();
  int a,b;
  cout<<"enter  the value of number 1 =”;
  cin>>a;
  cout<<"enter  the value of number 2";
  cin>>b;
  a=a+b;
  b=a-b;
  a=a-b;
  /*THIS PROGRAM ACCEPT TWO NUMBERS AS INPUT AND GENERATE TWO NUMBER IN OUTPUT BY     SWAPPING THEIR VALUES*/
  cout<<"\n"<<"after interchanging value of"<<" number 1 ="<<a<<"\n"<<" number  2="<<b;
  getch();

}

C++ PROGRAM TO FIND THE G.C.D OF TWO NUMBERS USING NON-RECURSIVE FUNCTIONS

/* C++ PROGRAM TO FIND THE G.C.D OF TWO NUMBERS USING NON-RECURSIVE FUNCTIONS */
#include<iostream.h>
#include<conio.h>
int gcd(int m,int n);
void main()
{
    int m,n;
    clrscr();
    cout<<"Enter m,n values :";
    cin>>m>>n;
    cout<<"The G.C.D of given two numbers :"<<gcd(m,n);
    getch();
}
int gcd(int m,int n)
{
    if(m==n)
        return m;
    else
    {
        int gcd;
        while(n!=0)
        {
            int d=m%n;
            if(d==0)
                gcd=n;
            m=n;
            n=d;
        }
        return gcd;
    }
}

/*   OUTPUT
     ------
     Enter m,n values :6 8
     The G.C.D of given two numbers :2
*/

C++ PROGRAM TO CONVERT THE ROMAN NUMERAL INTO AN ARABIC INTEGER

/* A C++ PROGRAM TO CONVERT THE ROMAN NUMERAL INTO AN ARABIC INTEGER  */
#include<iostream.h>
#include<conio.h>
void main()
{
char s[10];
int sum=0,i=0;
clrscr();
cout<<"Enter roman numeral :";
cin>>s;
while(s[i]!='\0')
{
switch(s[i])
{
case 'm':sum+=1000;
break;
case 'd':if(s[i-1]=='c')
sum+=400;
else if(s[i-1]=='l')
   sum+=450;
else
sum+=500;
break;
case 'c':if(s[i+1]!='d')
{
if(s[i-1]=='l')
sum+=50;
else
sum+=100;
}
break;
case 'l':if(s[i+1]!='c')
sum+=50;
break;
case 'x':if(s[i-1]=='i')
sum+=9;
else
sum+=10;
break;
case 'v':if(s[i-1]=='i')
sum+=4;
else
sum+=5;
break;
case 'i':if(s[i+1]!='x' || s[i+1]!='v')
sum+=1;
break;
default :cout<<"Invalid Roman numeral:";
}
i++;
}
cout<<"The equivalent Arabic integer is :"<<sum;
getch();
}

/* OUTPUT
------
Enter roman numeral :i
The equivalent Arabic integer is :1
*/