C · Lesson 2 of 3
📦 Variables in C
Store numbers and print them with format codes.
int stores whole numbers and float stores decimals. In printf, %d prints an int and %f prints a float.
#include <stdio.h>
int main() {
int apples = 5;
float price = 12.5;
printf("%d apples cost %.2f\n", apples, apples * price);
return 0;
}OUTPUT5 apples cost 62.50
💡 %.2f prints 2 numbers after the decimal point.
✏️ Your turn
Open this example in the playground, change it and run it.
🧠 Quick quiz