마살라

N1-->
Ikki nuqta orasidagi masofani hisoblab beradigan funksiya tuzing.
  • 노미: distance
  • 변수: int aX, int aY, int bX, int by
  • qaytarishi: shu ikki nuqta orasidagi masofani float sifatida qaytaradi.
    대답:

  • #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;
    }
    

    N2-->
    Berilgan nuqta aylana ichidami yo'qmi aniqlaydigan funksiya tuzing.
  • nomi: pointIsInCircle
  • 매개변수:
  • 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 요크사 false qaytaradi.
  • yuqorida yaratilgan distance funksiyasidan foydalaning.

  • 대답:

    #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;
    }
    

    좋은 웹페이지 즐겨찾기