
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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("
\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:
"); scanf("%f %f %f",&num1,&num2,&num3) ; printf ("number1 = %.1lf
", ceil(num1)); printf ("number2 = %.1lf
", ceil(num2)); printf ("number3 = %.1lf
", 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 Articles
- Explain the pre-processor directives in C language
- What are the Pre-processor Commands in C language?
- Post and Pre incremented of arrays in C language
- How to use POSIX semaphores in C language
- How to use the "defined?" keyword in Ruby?
- How to refer to a element that contains pre-defined options for an element in HTML?
- How to create a customized atoi() function in C language?
- isalnum() function in C Language
- isupper() function in C Language
- How to use clock() function in C++
- defined() function in PHP
- How to use pre-cooked rice to make other dishes?
- Pre-increment (or pre-decrement) in C
- How to check if a JavaScript function is defined?
- How to pass entire structure as an argument to function in C language?

Advertisements