Taking a float number and do several calculations. - C Language Basics

C examples for Language Basics:printf

Description

Taking a float number and do several calculations.

Demo Code

#include <stdio.h>

int main (){//w w w .j  a  v  a  2 s . co m
    float d = 6.5;
    float half, square, cube;

    half = d / 2;
    square = d * d;
    cube = d * d * d;

    printf("\nYour number is %.2f\n", d);
    printf("Half of it is %.2f\n", half);
    printf("Square it to get %.2f\n", square);
    printf("Cube it to get %.2f\n", cube);

    return 0;
}

Result


Related Tutorials