Intensive Programming Lab 3
Intensive Programming Lab 3
Learning Objectives:
The objectives of this first experiment are to make you familiar with data types, identifiers, basic
operators, expressions and basic input/output.
Example 1:
Code:
#include<iostream>
using namespace std;
/* function main begins program execution */
int main()
{
int num1=5; /* initializing an integer variable num1 to 5 */
int num2=9; /* initializing a variable num2 of integer data type */
int sum=0; /* variable sum in which sum will be stored */
sum= num1 + num2; /* Adding both number */
cout<<"The sum is: "<<sum;
Task 1: Write a C++ program to perform the basic arithmetic operations (addition, subtraction,
multiplication, division, remainder).
Example 2:
Write a C++ program that input two numbers from user and calculate their sum .
Code:
#include<iostream>
using namespace std;
/* function main begins program execution */
int main()
{
int num1, num2, sum; /* declairing variables */
cout<<"Enter two numbers";
cin>>num1>>num2; /*Reading two numbers from user */
sum= num1 + num2; /* Adding both number */
cout<<"The sum is: "<<sum; /* Display the result of addition */
Task 3: Write a C-Program to calculate area and Perimeter of the triangle and rectangle.
[Area of triangle= ½ x base x vertical height , Perimeter of triangle = a + b + c]
[Area of rectangle= width x height , Perimeter of rectangle = 2( a + b)]
Task 4: Write a C++ program to enter temperature in Fahrenheit and convert to Celsius.