Skip to content

Latest commit

 

History

History
140 lines (103 loc) · 1.94 KB

17. C Standard Library Function.md

File metadata and controls

140 lines (103 loc) · 1.94 KB

C Standard Library Functions

Video Link: https://youtu.be/OJvwk3pLK34
Tutorial Link: https://www.programiz.com/c-programming/library-function

Math Header File

Example 1:

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

int main() {

  int num = 25;
  printf("Square root is %lf", sqrt(num));

  return 0;
}

Output

Square root is 5.000000

Example 2:

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

int main() {

  int num = 27;
  printf("Cube root is %lf", cbrt(num));

  return 0;
}

Output

Cube root is 3.000000

Example 3:

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

int main() {

  int a = 5;
  int b = 2;

  double result = pow(a, b);
  printf("Power: %lf", result);

  return 0;
}

Output

Power: 25.000000

Ctype Header File

#include <stdio.h>
#include <ctype.h>

int main() {

  char alph = 'e';

  char upper = toupper(alph);
  printf("%c", upper);

  char lower = tolower(upper);
  printf("\n%c", lower);

  return 0;
}

Output

E
e

Programming Task

Create a program that computes the result of a number raised to the power of the square root of a number. So first.

  • Take input from user
  • Compute the square root of a number using sqrt()
  • Compute the power of the number raised to the power of its square root
  • Print the result

Solution :

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

int main() {
    double num;
    
    printf("Enter a number: ");
    scanf("%lf", &num);
    
    double square = sqrt(num);
    double power = pow(num, square);
    
    printf("The result is: %.2lf", power);
    
    return 0;
}

Output

Enter a number: 9
The result is: 729.000000

Programiz Quiz

Q. What is the correct way to include a library file in our program?

Options:

  1. Math.sqrt()

  2. #include <math.h>

  3. #include Math.sqrt()

  4. math.sqrt()

Answer: 2