Monday, December 1, 2014

C++ Excellant Pro



C++ program to convert decimal number to binary number

#include
#include
int main()
{
int n,x,a, c, k;
cout<<"Enter an integer in decimal number system";
cin>>x;
n=x;
cout<<"Binary value of given number is: ";
for( a=1;n!=0;a++)
{
n=n/2;
}
a=a-2;
for (c = a; c >= 0; c--)
{
k = x >> c;
if (k & 1)
cout<<"1";
else
cout<<"0";
}
return 0;

C++ program to find the area and perimeter of rectangle

#include
#include
using namespace std;
int main()
{
    int width,height,area,perimeter;
    cout<<"Enter  Width of Rectangle = ";
    cin>>width;
    cout<<"Enter  Height of Rectangle = ";
    cin>>height;
    area=height*width;
    cout<<"Area of Rectangle ="<     perimeter=2*(height+width);
cout<<" Perimeter of rectangle are = "< return 0;
}

C++ program to find the area of triangle using heron’s formula

#include
#include
using namespace std;
int main()
{
    float first,second,third;
    float s,area;
    cout<<"Enter size of each sides of triangle"<     cout<<"Enter size for first side =";
    cin>>first;
    cout<<"Enter size for second side =";
    cin>>second;
    cout<<"Enter size for third side =";
    cin>>third;
    s = (first+second+third)/2;
    area = sqrt(s*(s-first)*(s-second)*(s-third));
    cout<<"Area of triangle= "<     return 0;
}

C++ program to swap the values of two integers

#include
#include
using namespace std;
int main()
{
int var1, var2, swap;
 cout<<"Enter value for first integer:  ";
 cin>>var1;
 cout<<"Enter value for second integer:  ";
 cin>>var2;
 cout<<" Values before swapping:  "<  cout<<"First integer ="<  cout<<"Second interger ="<               swap=var1;
              var1=var2;
              var2=swap;
 cout<<" Values after swapping:  "<  cout<<"First integer ="<  cout<<"Second interger ="<  return 0;
}

No comments:

Post a Comment