Declaring Variables
Variables are used to hold a value. It can be a text or numbers or even
both. This is very useful in programming especially when you want to display some
text/numbers multiple times.
There are types of variables used to make a program. These will give the
variables a classification that the computer will understand.
On this part, we will create a simple mathematical addition. Here is
the code.
Looking at the codes, we used int type of variable. It is used because we are using variables to hold numeric values.
x, y and z are the variables that we declared. You can use any
alphanumeric characters to declare variables. It can be (A, B, C) , (num1,num2,num3), or it can be a name of your choice.
The x has a value of 100 and y has 200, but z doesn’t have a value. It’s
ok, we can declare a value for z later.
printf("Value of X is = %d \n", x); //---- %d will call the integer value of
x
printf("Value of Y is = %d \n", y); //---- %d will call the integer value of
y
This statement will display a text and a variable.
The backslash followed by letter n “\n” will begin a new line.
z=x+y;
printf("The sum of X and Y is = %d", z);
This line will declare the value of z.
z=x+y , it is clear that the value of z will add the
value of x and y. And the last
part will print the value of z.
No comments:
Post a Comment