Write a C Program to calculate
the area of triangle using the formula
area = ( s (s-a)
(s-b)(s-c))1/2 where s= (a+b+c)/2
SOURCE CODE:
/*Program to Find Area of Triangle.*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,s,area;
clrscr();
printf("Enter size of sides of triangle::");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2.0;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("\nThe area of triangle is %.2f",area);
}
OUTPUT:
Write a C program to find the
largest of three numbers using ternary operator.
SOURCE CODE:
/*Program to Find Largest Among Three Numbers Using Ternary Operator.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,largest;
clrscr();
printf("Enter three numbers:");
scanf("%d%d%d",&a,&b,&c);
largest=((a>b)&&(a>c))?a:(((b>a)&&(b>c))?b:c);
printf("\nLargest among three numbers is %d",largest);
}
OUTPUT:
Write
a C Program to swap two numbers without using a temporary variable.
SOURCE CODE:
/*Program to Swap Two Numbers without using Temporary Variable.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter two numbers:");
scanf("%d%d",&a,&b);
printf("\nBefore Swapping::\na=%d\tb=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter Swapping::\na=%d\tb=%d",a,b);
}
OUTPUT:
Write a C Program to calculate
the area of triangle using the formula
area = ( s (s-a)
(s-b)(s-c))1/2 where s= (a+b+c)/2
SOURCE CODE:
/*Program to Find Area of Triangle.*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,s,area;
clrscr();
printf("Enter size of sides of triangle::");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2.0;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("\nThe area of triangle is %.2f",area);
}
OUTPUT:
Write a C program to find the
largest of three numbers using ternary operator.
SOURCE CODE:
/*Program to Find Largest Among Three Numbers Using Ternary Operator.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,largest;
clrscr();
printf("Enter three numbers:");
scanf("%d%d%d",&a,&b,&c);
largest=((a>b)&&(a>c))?a:(((b>a)&&(b>c))?b:c);
printf("\nLargest among three numbers is %d",largest);
}
OUTPUT:
Write
a C Program to swap two numbers without using a temporary variable.
SOURCE CODE:
/*Program to Swap Two Numbers without using Temporary Variable.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter two numbers:");
scanf("%d%d",&a,&b);
printf("\nBefore Swapping::\na=%d\tb=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter Swapping::\na=%d\tb=%d",a,b);
}
OUTPUT: