-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariables.c
41 lines (34 loc) · 1.42 KB
/
variables.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* @file variables.c
* @brief Example of a simple C program that shows how variables are declared and used.
*/
#include <stdio.h>
int main(int argc, char *argv[])
{
// Declare and initialize variables
int an_integer = 5; // Integer variable
float a_float = 3.14f; // Floating-point variable
char a_char = 'A'; // Character variable
int another_integer; // Declare an integer variable
int yet_another_integer; // Declare another integer variable
// Assign values to variables
another_integer = 10;
yet_another_integer = 20;
// Print the values of variables
printf("an_integer = %d\n", an_integer);
printf("a_float = %f\n", a_float);
printf("a_char = %c\n", a_char);
printf("another_integer = %d\n", another_integer);
printf("yet_another_integer = %d\n", yet_another_integer);
// Perform arithmetic operations
int sum = an_integer + another_integer;
int difference = another_integer - yet_another_integer;
int product = an_integer * yet_another_integer;
float quotient = a_float / an_integer;
// Print the results of arithmetic operations
printf("an_integer + another_integer = %d\n", sum);
printf("another_integer - yet_another_integer = %d\n", difference);
printf("an_integer * yet_another_integer = %d\n", product);
printf("a_float / an_integer = %f\n", quotient);
return 0;
}