PPSC EXERCISE-2

 

EXERCISE-2

1. Write a C program to calculate the distance between the two points.
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:
Enter x1 and x2 : 5 9
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:
Enter p,q,r,s values:4 8 2 13
Correct values
OUTPUT-2:
Enter p,q,r,s values:9 3 1 45
Wrong values

No comments

Algorithms and Programs

  Algorithms and Programs Both the algorithms and programs are used to solve problems, but they are not the same things in terms of their fu...