Tutorial references

c
c++
c#

Tutorial references

chapters

Math in C (math.h)

Math

First include math.h header file.

abs

abs() returns the absolute value of given number.

Example

#include <stdio.h>
#include <conio.h>
#include <math.h>

void main()
{
int n, result;
clrscr();
printf("Enter number: ");
scanf("%d", &n);
result = abs(n);
printf("\n Absolute value of %d = %d", n, result);
getch();
}

Run program

ceil

It rounds up the given number. It returns the integer value which is greater than or equal to given number.

Example

#include <stdio.h>
#include <conio.h>
#include <math.h>

void main()
{
float n;
int result;
clrscr();
printf("Enter number: ");
scanf("%f", &n);
result = ceil(n);
printf("\n ceil value of %f = %d", n, result);
getch();
}

Run program

floor

It rounds down the given number. It returns the integer value which is less than or equal to given number.

Example

#include <stdio.h>
#include <conio.h>
#include <math.h>

void main()
{
float n;
int result;
clrscr();
printf("Enter number: ");
scanf("%f", &n);
result = floor(n);
printf("\n floor value of %f = %d", n, result);
getch();
}

Run program

sqrt

Returns the square root of given number.

Example

#include <stdio.h>
#include <conio.h>
#include <math.h>

void main()
{
float n;
float result;
clrscr();
printf("Enter number: ");
scanf("%f", &n);
result = sqrt(n);
printf("\n square root of %f = %f", n, result);
getch();
}

Run program

pow

Returns the power of given number.

Example

#include <stdio.h>
#include <conio.h>
#include <math.h>

void main()
{
float n;
float result;
int exp;
clrscr();
printf(" Enter base value: ");
scanf("%f", &n);
printf("\n Enter exponent value: ");
scanf("%d", &exp);
result = pow(n, exp);
printf("\n result = %f", result);
getch();
}

Run program

About Us

This website(www.sabbla.com) is very useful for beginners and professional developers. Sabbla provides tutorial in simple language. It provides latest technology tutorial which very useful for developers.

See More...

Contact Us

+91 9971366710

+91 9717983128

info@sabbla.com

Buxar, Bihar, India, Pin No.- 802131

Services

Sabbla is providing free latest technology tutorials. All tutorials are free for beginner and professionals.


Terms of Use

sabbla.com is not responsible for any mistake. Users can inform to sabbla.com for any mistake. But sabbla.com always try for 0-0 mistake.

Privacy policy

Currently sabbla.com does not collect any data from users.

                   

copyright © 2017-2018