HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to CVariablesData TypesOperatorsStringsArraysConditions (if / switch)Loops (for / while)FunctionsPointers
REFERENCE
📖 Overview
🖥️ Output & Input
📦 Variables
🔢 Numbers & Math
Arithmetic ( + - * / % )math.h (sqrt / pow)
✍️ String
📋 Array
🔁 Condition & Loop
🧩 Function
👉 Pointer
C›REFERENCE›Numbers & Math
🔢

Numbers & Math

Arithmetic and math.h.

CommandDescription
Arithmetic ( + - * / % )Four basic operations and remainder.
math.h (sqrt / pow)Math functions.

Arithmetic ( + - * / % )

Try it yourself →

Four basic operations and remainder.

Syntax

a + b, a % b

Description

Integer division truncates the decimal: 7 / 2 = 3. Use float/double for decimals.

Example

#include <stdio.h>
int main() {
    printf("%d\n", 7 % 2);
    printf("%d\n", 7 / 2);
    printf("%.1f\n", 7.0 / 2);
    return 0;
}

Expected output

1
3
3.5

When to use?

Calculations.

Common mistakes

  • ⚠️ 7 / 2 = 3 (int division). Use 7.0 / 2 for decimals.

math.h (sqrt / pow)

Try it yourself →

Math functions.

Syntax

sqrt(x)  (#include <math.h>)

Description

sqrt for square root, pow for exponentiation. Requires math.h. Result is a double (printed with %f).

Example

#include <stdio.h>
#include <math.h>
int main() {
    printf("%.1f\n", sqrt(144));
    printf("%.1f\n", pow(2, 10));
    return 0;
}

Expected output

12.0
1024.0

When to use?

Geometry, exponential calculations.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code