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;
}
#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 = "<
}
C++ program to find the area of
triangle using heron’s formula
#include
#include
#include
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;
}
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: "<
var1=var2;
var2=swap;
cout<<" Values after swapping: "<
}
No comments:
Post a Comment