
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use Pre-defined mathematical function in C language?
Problem
How to find the cube root of any given number by using the C programming language?
Solution
Algorithm
Step 1: Enter any number at run time Step 2: Read from console Step 3: Compute result Result:pow(number,1.0/3.0) Step 4: Increment result Step 5: Print result
Example
Following is the C program to find the cube root of any given number −
//finding cube root of given number// #include<stdio.h> #include<conio.h> #include<math.h> void main(){ int number, result; printf("Enter any number: "); scanf("%d",&number); result=pow(number, 1.0/3.0); result++; printf("\n\Cube of %d is: %d",number,result); getch(); }
Output
When the above program is executed, it produces the following result −
Cube of 4 is 64
Example
Consider another example by using math function.
#include <stdio.h> #include <math.h> int main (){ float num1, num2, num3; printf("enter 3 numbers:\n"); scanf("%f %f %f",&num1,&num2,&num3) ; printf ("number1 = %.1lf\n", ceil(num1)); printf ("number2 = %.1lf\n", ceil(num2)); printf ("number3 = %.1lf\n", ceil(num3)); return(0); }
Output
When the above program is executed, it produces the following result −
enter 3 numbers: 3.7 -4.2 -6.7 number1 = 4.0 number2 = -4.0 number3 = -6.0
- Related Questions & Answers
- Explain the pre-processor directives in C language
- Post and Pre incremented of arrays in C language
- What are the Pre-processor Commands in C language?
- How to use POSIX semaphores in C language
- defined() function in PHP
- isalnum() function in C Language
- isupper() function in C Language
- Pre-increment (or pre-decrement) in C
- How to use clock() function in C++
- How to use pre-cooked rice to make other dishes?
- C++ Mathematical Functions
- Mathematical Functions in C#
- How to create a customized atoi() function in C language?
- Explain Squeeze Function C language
- fgetc() function in C Programming Language
Advertisements