C_Programming_Concepts
C_Programming_Concepts
Different data
types determine the type of data that can be stored.
Some common data types include:
1. int: Integer data type (e.g., 5, -10)
2. float: Floating-point data type (e.g., 3.14, -0.5)
3. char: Character data type (e.g., 'a', 'X')
4. double: Double-precision floating-point data type
(e.g., 3.14159)
Declare Variable & Create Variable
// Declare a variable
int myNum;
// Assign a value to the variable
myNum = 15;
Example
int dice = 1;
while (dice <= 6) {
if (dice < 6) {
printf("No Yatzy\n");
} else {
printf("Yatzy!\n");
}
dice = dice + 1;
}
The for loop in C is used to execute a block of code a
specified number of times. It consists of three parts:
initialization, condition, and increment/decrement.
Example
int number = 2;
int i;
// Print the multiplication table for the number 2
for (i = 1; i <= 10; i++) {
printf("%d x %d = %d\n", number, i, number * i);
}
return 0;
int number = 2;
int i;
return 0;