DEV Community

NilufarBukhorova
NilufarBukhorova

Posted on

Masala

N1-->
Ikki nuqta orasidagi masofani hisoblab beradigan funksiya tuzing.

  • nomi: distance
  • parametrlari: int aX, int aY, int bX, int bY
  • qaytarishi: shu ikki nuqta orasidagi masofani float sifatida qaytaradi. Answer:
#include <iostream>
#include <cmath>

using namespace std;

  float distance(int aX, int aY, int bX, int bY)
{
  int a= aY - bY;
  int b= aX - bY;

  int cKvadrat = a*a + b*b;

  int c = sqrt(cKvadrat); //square root

  return c;
  //return sqrt(pow(aY - bY,2)+ pow(aX - bY,2))
}

int main() 
{
  cout << distance(5,6,2,2);
 return 0;
}
Enter fullscreen mode Exit fullscreen mode

N2-->
Berilgan nuqta aylana ichidami yo'qmi aniqlaydigan funksiya tuzing.

  • nomi: pointIsInCircle
  • parametrlar:
    • aylana markazini anglatuvchi int cX, int cY
    • aylana radiusini anglatuvchi int cRadius
    • nuqta koordinasini anglatuvchi int pX, int pY
  • qaytarishi: berilgan nuqta aylana ichida bo'lsa true yo'qsa false qaytaradi.
  • yuqorida yaratilgan distance funksiyasidan foydalaning.

Answer:

#include <iostream>
#include <cmath>

using namespace std;
float distance(int aX, int aY, int bX, int bY)
{
  int a= aY - bY;
  int b= aX - bY;

  int cKvadrat = a*a + b*b;

  int c = sqrt(cKvadrat); //square root

  return c;
  //return sqrt(pow(aY - bY,2)+ pow(aX - bY,2))
}
bool pointIsInCircle(int cX, int cY, int cRadius, int pX, int pY)
{
  return distance(cX, cY, pX, pY) < cRadius;
}

int main() 
{
  cout << pointIsInCircle(3,3,2,5,5) << endl;
 return 0;
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)