Feedback Form

Math Library Functions in C in Hindi

Introduction to Math Library Functions in C in Hindi

Introduction to Math Library Functions in C in Hindi

What are Math Library Functions?

C language में Math Library Functions का उपयोग तब किया जाता है जब हमें गणित से जुड़ी कोई विशेष गणना करनी होती है, जैसे – किसी संख्या की शक्ति (power), वर्गमूल (square root), पूर्णांक भाग (ceil या floor), इत्यादि। ये functions पहले से C की math.h नाम की header file में बनाए गए होते हैं। इनका उपयोग करके हम complex गणनाएं बहुत आसानी से कर सकते हैं।

Why use Math Functions?

  • बार-बार उपयोग होने वाली गणनाएं आसानी से की जा सकती हैं।
  • Program का code छोटा और clean होता है।
  • इन functions को प्रयोग करने से error की संभावना कम होती है।
  • यह functions highly optimized होते हैं और fast execution देते हैं।

Where are Math Functions defined?

C में ये सभी functions math.h header file में पहले से define होते हैं। जब भी हम किसी program में इन functions का उपयोग करना चाहते हैं तो हमें सबसे पहले #include लिखना होता है।

Use of pow(), sqrt(), abs(), and ceil() functions in Hindi

1. pow() Function

pow() function का उपयोग किसी संख्या की शक्ति (power) निकालने के लिए किया जाता है।
Syntax: double pow(double base, double exponent);
उदाहरण: #include
#include
int main() {
  double result = pow(2, 3);
  printf("%lf", result); // Output: 8.000000
  return 0;
}

2. sqrt() Function

sqrt() function का उपयोग किसी संख्या का वर्गमूल (square root) निकालने के लिए किया जाता है।
Syntax: double sqrt(double number);
उदाहरण: #include
#include
int main() {
  double result = sqrt(16);
  printf("%lf", result); // Output: 4.000000
  return 0;
}

3. abs() Function

abs() function का उपयोग किसी integer संख्या का absolute value (positive value) निकालने के लिए किया जाता है।
Syntax: int abs(int number);
उदाहरण: #include
#include
int main() {
  int result = abs(-10);
  printf("%d", result); // Output: 10
  return 0;
}

4. ceil() Function

ceil() function का उपयोग किसी दशमलव संख्या को नजदीकी बड़ा पूर्णांक (nearest greater integer) में बदलने के लिए किया जाता है।
Syntax: double ceil(double number);
उदाहरण: #include
#include
int main() {
  double result = ceil(5.2);
  printf("%lf", result); // Output: 6.000000
  return 0;
}

Header files required for Math Functions in Hindi

आपका अगला टॉपिक पढ़े What are Character Functions in C Language in Hindi

C language में mathematical functions को use करने के लिए आपको नीचे दिए गए header files को include करना आवश्यक होता है:

  • #include — यह सभी floating point based functions जैसे pow(), sqrt(), ceil(), floor(), log() आदि के लिए जरूरी है।
  • #include — यह abs() जैसे integer-based function के लिए जरूरी है।

यदि आप इन header files को include नहीं करते हैं तो compiler error देगा जैसे – "implicit declaration of function" या "undefined reference"।

Real-time examples of Mathematical Functions in C in Hindi

आपका अगला टॉपिक पढ़े Declaration Statement Syntax and Rules in Hindi

उदाहरण 1: EMI Calculation में Power Function का उपयोग

जब हम बैंक से loan लेते हैं तो EMI की गणना के लिए हमें power function की जरूरत होती है। जैसे:

EMI = P × R × (1+R)^N / ((1+R)^N - 1)

यहाँ (1+R)^N के लिए pow() function उपयोग किया जाता है।

उदाहरण 2: Circle का Area निकालना

#include
#include
int main() {
  float radius = 5;
  float area = 3.14 * pow(radius, 2);
  printf("Area: %f", area);
  return 0;
}

उदाहरण 3: Temperature Sensor से Data लेना

मान लीजिए temperature sensor ने 36.7 दिया, लेकिन हमें ceiling value चाहिए यानी integer value के रूप में।

#include
#include
int main() {
  float temperature = 36.7;
  int temp = ceil(temperature);
  printf("Temperature (Ceil): %d", temp);
  return 0;
}

उदाहरण 4: Distance Calculation में Square Root

दो बिंदुओं के बीच की दूरी के लिए हमें sqrt() function का उपयोग करना होता है:

#include
#include
int main() {
  int x1 = 2, y1 = 3, x2 = 6, y2 = 7;
  double distance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
  printf("Distance: %lf", distance);
  return 0;
}

FAQs

math.h header file का उपयोग mathematical functions जैसे sqrt(), pow(), ceil() आदि को प्रयोग करने के लिए किया जाता है।
pow(x, y) function x की y घात (power) को return करता है, जैसे pow(2,3) = 8।
abs() सिर्फ integer values के लिए है जबकि fabs() floating-point numbers के लिए प्रयोग होता है।
अगर math.h file include नहीं की जाती तो program compile तो हो सकता है लेकिन run-time पर error देगा या wrong output आएगा।
ceil() function हमेशा double type value return करता है, लेकिन आप उसे integer में cast कर सकते हैं।