C Program to Find Square, Cube and Square Root of a Number किसी संख्या का वर्ग, घन एवं वर्गमूल ज्ञात करने का प्रोग्राम

In C language, mathematical functions are used to calculate the square, cube, and square root of a number. The pow() function calculates powers, while the sqrt() function calculates the square root.

सी लैंग्वेज में किसी संख्या का वर्ग, घन तथा वर्गमूल ज्ञात करने के लिए गणितीय फंक्शन्स का प्रयोग किया जाता है। pow() फंक्शन किसी संख्या की घात ज्ञात करता है, जबकि sqrt() फंक्शन वर्गमूल ज्ञात करता है।

Formulas सूत्र:

  • Square (वर्ग): (n^2 = n \times n)

  • Cube (घन): (n^3 = n \times n \times n)

  • Square Root (वर्गमूल): (\sqrt{n})

C Program

#include <stdio.h>
#include <math.h>
int main(void)
{
float n, square, cube, sr;
printf("Enter a number: ");
scanf("%f", &n);
square = pow(n, 2);
cube = pow(n, 3);
printf("Square of %.2f = %.2f\n", n, square);
printf("Cube of %.2f = %.2f\n", n, cube);
if (n >= 0)
{
sr = sqrt(n);
printf("Square root of %.2f = %.2f\n", n, sr);
}
else
{
printf("Square root of a negative number is not a real number.\n");
}
return 0;
}

Output

Enter a number: 4
Square of 4.00 = 16.00
Cube of 4.00 = 64.00
Square root of 4.00 = 2.00

Explanation व्याख्या:

In this program, the user enters a number that is stored in variable n.

इस प्रोग्राम में यूजर एक संख्या इनपुट करता है, जिसे n वेरिएबल में स्टोर किया जाता है।

The statement square = pow(n, 2); calculates the square of the number, and cube = pow(n, 3); calculates its cube.

स्टेटमेंट square = pow(n, 2); संख्या का वर्ग ज्ञात करता है तथा cube = pow(n, 3); उसका घन ज्ञात करता है।

The statement sr = sqrt(n); calculates the square root when n is non-negative.

स्टेटमेंट sr = sqrt(n); तब संख्या का वर्गमूल ज्ञात करता है जब n शून्य या धनात्मक हो।

The math.h header file declares the pow() and sqrt() functions. Some compilers, such as GCC on certain platforms, may require linking the math library using -lm.

math.h हैडर फाइल में pow() तथा sqrt() फंक्शन्स के डिक्लेरेशन उपलब्ध होते हैं। कुछ कम्पाइलर्स, जैसे कुछ प्लेटफॉर्म पर GCC, में मैथ लाइब्रेरी को -lm की सहायता से लिंक करना पड़ सकता है।

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Top High-Paying Tech Skills to Learn in 2025

Complete C Programming Syllabus | Advanced C Roadmap for Students