Senin, 01 Desember 2025

ex1105.c include math.h

/* ex1105.c */
#include <stdio.h>
#include <math.h>

int main()
{
    float result,value;

    printf("Input float value: ");
    scanf("%f",&value);

    result=sqrt(value);
    printf("The square root of %.2f is %.2f\n",value,result);

    result=pow(value,3);
    printf("%.2f to the 3rd power is %.2f\n",value,result);

    result=floor(value);
    printf("The floor of %.2f is %.2f\n",value,result);

    result=ceil(value);
    printf("And the ceiling of %.2f is %.2f\n",value,result);

    return(0);
}

output:
 
Input float value: 15
The square root of 15.00 is 3.87
15.00 to the 3rd power is 3375.00
The floor of 15.00 is 15.00
And the ceiling of 15.00 is 15.00

Process returned 0 (0x0)   execution time : 1.216 s
Press any key to continue.

Fungsi sqrt(), pow(), ceil(), floor() perlu meng-include-kan file header math.h. Sedangkan fungsi abs() butuh file header stdlib.h.

Tidak ada komentar:

Posting Komentar