1. Write a C program to calculate the distance between the two points.
SOURCE CODE:
2. Write a C program that accepts 4 integers p, q, r, s from the user where r and s are positive and p is even. If q is greater than r and s is greater than p and if the sum of r and s is greater than the sum of p and q print "Correct values", otherwise print "Wrong values".
SOURCE CODE:
SOURCE CODE:
#include<stdio.h>
#include<math.h>
int main(){
float x1,x2,y1,y2,dist;
printf("Enter x1 and x2 : ");
scanf("%f%f",&x1,&x2);
printf("Enter y1 and y2 : ");
scanf("%f%f",&y1,&y2);
dist = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
printf("Distance between two points : %f\n",dist);
return 0;
}
OUTPUT:#include<math.h>
int main(){
float x1,x2,y1,y2,dist;
printf("Enter x1 and x2 : ");
scanf("%f%f",&x1,&x2);
printf("Enter y1 and y2 : ");
scanf("%f%f",&y1,&y2);
dist = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
printf("Distance between two points : %f\n",dist);
return 0;
}
Enter x1 and x2 : 5 9
Enter y1 and y2 : 4 8
Distance between two points : 5.656854
Enter y1 and y2 : 4 8
Distance between two points : 5.656854
2. Write a C program that accepts 4 integers p, q, r, s from the user where r and s are positive and p is even. If q is greater than r and s is greater than p and if the sum of r and s is greater than the sum of p and q print "Correct values", otherwise print "Wrong values".
SOURCE CODE:
#include<stdio.h>
int main(){
int p,q,r,s;
printf("Enter p,q,r,s values:");
scanf("%d%d%d%d",&p,&q,&r,&s);
if(r>0 && s>0 && p%2==0 && q>r && s>p && r+s>p+q)
printf("Correct values");
else
printf("Wrong values");
return 0;
}
OUTPUT-1:int main(){
int p,q,r,s;
printf("Enter p,q,r,s values:");
scanf("%d%d%d%d",&p,&q,&r,&s);
if(r>0 && s>0 && p%2==0 && q>r && s>p && r+s>p+q)
printf("Correct values");
else
printf("Wrong values");
return 0;
}
Enter p,q,r,s values:4 8 2 13
Correct values
OUTPUT-2:Correct values
Enter p,q,r,s values:9 3 1 45
Wrong values
Wrong values