Programming Fund Lab 01
Programming Fund Lab 01
Defining Variables:
�A variable must be defined before you can use it in a program. When you
define a variable,
the type is specified and an appropriate amount of memory reserved. This
memory space is
addressed by reference to the name of the variable. �
Valid Declaration:-
1. Int i, a, j;
2. Char c, ch;
3. Float f, salary
4. Double d;
1. A variable name can only have alphabets, numbers, and the underscore _.
2. A variable name cannot begin with a number.
3. It is a preferred practice to begin variable names with a lowercase
character. For example, name is preferable to Name.
4. A variable name cannot be a keyword. For example, int is a keyword that
is used to denote integers.
5. A variable name can start with an underscore. However, it's not
considered a good practice.
1. Int myNum= 5;
2. Float myfloat = 3.1234567;
3. Double myFloatNumber= 5.99999999999;
4. Char myChar = �d�;
5. String myText = �hello�;
6. Bool myBoolean= true;
Task 1:
Write a C++ program that two defines variables for floating-point numbers and
initializes them with the values 123.456 and 76.543. Then display the sum
and the difference of these two numbers on screen.
Solution:
#include <iostream>
int main()
{
float num1 = 123.456;
float num2 = 76.543;
float num3 = num1 + num2;
float num4 = num1 - num2;
cout<<"sum of two number:"<<num3<<endl;
cout<<"diff of two number:"<<num4;
}