1. Wap to swap the value of two variables without using third variable.
Program:
#include<stdio.h>
void main()
{
int x,y;
printf("enter the value of x,y");
scanf ("%d%d",&x,&y);
printf("x=%d and y=%d\n",x,y);
y=x*y;
x=y/x;
y=y/x;
printf("x=%d and y=%d",x,y);
}
OUTPUT:
Enter the value of two variables 10 20
x=10 and y=20
y=20 and x=10
[Link] to find out the area of a triangle using the following formula.
Area=√ s (s−a)(s−b)(s−c )
Where S=(a+b+c)/2
Program:
#include<stdio.h>
#include<math.h>
void main()
float a,b,c,s,area;
printf("enter the value of a,b and c");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("s=%f area=%f",s,area);
OUTPUT:
Enter the value of a,b.c
5 6 4
S=7.500000 area=9.91567
[Link] to accepts three integers and prints the largest among them.
Program:
#include <stdio.h>
void main()
{
int A, B, C;
printf("Enter three numbers ");
scanf("%d %d %d", &A, &B, &C);
if(A >B)
{
if (A > C)
{
printf("A is the largest");
}
else
{
printf("C is the largest");
}
}
else if(B>C)
{
printf("B is the largest");
}
else
{
printf("C is the largest");
}
OUTPUT:
Enter three numbers 10 20 30
C is the largest