The Binary Value of Decimal
Number using for loop
#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;
}
The area of any triangle using heron's formula
#include
#include
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= "<
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;
}
}
Swap two variables without
using third variable
#include
#include
int main()
{
int var1, var2;
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 ="<
var1=var1+var2;
var2=var1-var2;
var1=var1-var2;
cout<<" values after swapping: "<
cout<<"first integer ="<
cout<<"second interger ="<
{
int var1, var2;
cout<<"enter value for first integer: ";
cin>>var1;
cout<<"enter value for second integer: ";
cin>>var2;
cout<<" values before swapping: "<
var1=var1+var2;
var2=var1-var2;
var1=var1-var2;
cout<<" values after swapping: "<
return 0;
}
}
No comments:
Post a Comment