Learning Activity 1 - Problem Based Activity
Code Given:
#include <stdio.h>
#define PI 3.14
int main() {
int radius = 5;
float area;
area = PI * radius * radius;
printf("Area of circle is: %.2f\\n", area);
return 0;
}
Analysis:
1. Variables:
- radius (int variable, stores value 5)
- area (float variable, stores calculated area)
2. Constants:
- PI (defined using #define, value = 3.14)
3. Literals:
- 5 (integer literal, assigned to radius)
- 3.14 (floating-point literal, assigned to PI)
- "%.2f\\n" (string literal, format specifier in printf)
4. Identifiers:
- main, radius, area, PI, printf (names given to elements in the program)
Conclusion:
- Variables are storage locations whose values can change.
- Constants hold fixed values throughout the program.
- Literals are actual fixed values used directly in code.
- Identifiers are user-defined names given to variables, constants, functions, etc.