Friday, November 21, 2014

C Calculate area of square



C Program to Calculate Area of Circle

 #include
 #include
int main()
 {
   float radius, area;
    printf("\nenter the radius of circle : ");
   scanf("%d", &radius);
    area = 3.14 * radius * radius;
   printf("\narea of circle : %f", area);
    return (0);
}

Output

Enter the radius of Circle : 2.0
Area of Circle : 6.14

C Program to Calculate Area of Rectangle

#include
#include
int main() 
{
   int length, breadth, area;
   printf("\nenter the length of rectangle : ");
   scanf("%d", &length);
   printf("\nenter the breadth of rectangle : ");
   scanf("%d", &breadth);
   area = length * breadth;
   printf("\narea of rectangle : %d", area);
   return (0);
}

Output

Enter the Length of Rectangle  : 5
Enter the Breadth of Rectangle : 4
Area of Rectangle : 20

C Program to Calculate Area of Square

#include
#include 
int main()
{
   int side, area;
   printf("\nenter the length of side : ");
   scanf("%d", &side);
   area = side * side;
   printf("\narea of square : %d", area);
   return (0);
}

Output

Enter the Length of Side : 5
Area of Square : 25

C Program to check the type of triangle

#include

#include

int main()

{

int side1, side2,side3;

side1=5;

side2=4;

side3=3;

if((side1+side2>side3&&side1+side3>side2&&side2+side3>side1)&&(side1>0&&side2>0&&side3>0))

{

if(side1==side2&&side2==side3)

{

printf("equilateral triangle");

}

else if(side1==side2==||side2==side3||side1==side3)

{

printf("isosceless triangle");

 

else

{

printf("scalene triangle");

}

else

{

printf("triangle formation not possible");

}

return 0;

}

Output

Enter the values of sides: 3      3        2
Isosceles triangle

C Program to count trailing zeros using bitwise operator

 #include
#include
void printbinary(int num)
{
int mask=0x4000;
if((num&0x8000)==0)
printf("0");
else
printf("1");
while(mask!=0)
{
if((num&mask)==0)
printf("0");
else
printf("1");
mask=mask>>1;
}
}
void main()
{
int i,count=0;
unsigned int num;
printf("\n enter the number: ");
scanf("%d",&num);
printf("\n decimal number in binary format: ");
printbinary(num);
while(num!=0)
{
if(num&1==1)
{
break;
}
else
{
count++;
num=num>>1;
}
}
printf("\n trailing zeros : %d",count);
getch();
}

Output

Enter the number :120
Decimal number in binary format:0000000001111000
Trailing zeros :3

No comments:

Post a Comment