C Programming Basics: Examples and Explanations
Classified in Computers
Written on in
English with a size of 2.72 KB
C Programming Basics
Printing a Message
int main() { print("Hello!!!"); }
Variables and Mathematical Calculations
int main() // Main function
{
int a = 25; // Initialize a variable to 25
int b = 17; // Initialize b variable to 17
int c = a + b; // Initialize c variable to a + b
print("c = %d ", c); // Display decimal value of c
}
Floating-Point Math
int main() // Main function
{
float r = 1.0; // Set radius to 1.0
float c = 2.0 * PI * r; // Calculate circumference
print("circumference = %f \n", c); // Display circumference
}
Arrays
int main() // Main function
{
int p[] = {1, 2, 3, 5, 7, 11}; // Initialize the array
print("p[0] = %d\n", p[0]); // Display what p[0] stores
print("p[3] = %d\n", p[3]); // Display what p[3] stores
p[3] = 101; // Assignment
}

COLEGIO LEONARDO DA VINCI
