Lab 01
Lab 01
#include<iostream>
Using namespace std;
Int main()
{
Cout<< “Hello World!”;
Return 0;
}
The main function -int main (), int > return type integer, main > name of the
function, ( ) > argument list or list of parameters
Variable
A variable is used to hold a value, it is a place in the computer memory which needs to be
declared inside the body of program. Variable has 4 basic parameters:
1. Name
2. Data type
3. Value
4. Address
The value of variable can be changed after its declaration. On the other hand, constants have a
fixed value once they are declared. Every variable has some data type e.g., int, float, char, long,
double etc. Datatypes will be discussed in detail in lab 2. When a variable is declared, it takes
some memory and possesses some address.
in the above example, variable a and b are declared as well as instantiated while variable sum is
just declared.
Try Example
#include<iostream>
using namespace std;
int main()
{
int a=10;int b=20;int sum;
cout<<"The value of a is "<<a<<endl;
cout<<"This value of b is "<<b<<endl;
sum=a+b;
cout<<"The sum is "<<sum;
return 0;
}
Lab Tasks
1. Write a C++ program that takes two inputs from the user and calculates their
sum. Display the result.
2. Write a C++ program that takes three integer inputs, calculates their average,
and displays output.
3. Write a C++ program which calculated area of circle by taking radius from
user.
4. Append the above program and calculate the volume of a sphere.
5. Write a C++ program to calculate (𝑎 + 𝑏)2 .