0% found this document useful (0 votes)
17 views

Manual Intensive Programming Lab 3

Uploaded by

M Shahid Hanif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Manual Intensive Programming Lab 3

Uploaded by

M Shahid Hanif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Intensive Programming Lab

Lab 3: The Programming Environment

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:

Write a C++ program that finds the sum of two numbers.

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;

return 0; /* indicate that program ended successfully */

} /* end function main */

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 */

return 0; /* indicate that program ended successfully */

} /* end function main */

Task 2: Write a C++ program that input two numbers from user and calculate basic arithmetic
operations (addition, subtraction, multiplication, division, remainder).

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.
Task 1&2:
#include<iostream>
using namespace std;
int main()
{
/*Airthematic operations*/
int a,b;
float sum,div,sub,mul,remainder;
cout<<"value of a ";
cin>>a;
cout<<"value of b ";
cin>>b;

sum = a+b;
sub = a-b;
mul = a*b;
div = a/b;
remainder =a%b;

cout<<"sum is "<<sum<<endl;
cout<<"sub is "<<sub<<endl;
cout<<"mul is "<<mul<<endl;
cout<<"div is "<<div<<endl;
cout<<"remainder is "<<remainder<<endl;
}
Output:
Task 3:
#include <iostream>
using namespace std;
int main()
{
cout<<"write a programme for to find area and perimeter
of triangle";

int a,b,c;
float area,perimeter;

cout<<"\nvalue of a ";
cin>>a;
cout<<"value of b ";
cin>>b;

area = 0.5*a*b;

cout<<"area is "<<area<<endl;
cout<<"value of c ";
cin>>c;

perimeter = a+b+c;
cout<<"perimeter is "<<perimeter<<endl;
}
Output:
Task 3:
#include <iostream>
using namespace std;
int main()
{
cout<<"write a programme for to find area and perimeter
of rectangle";

int a,b;
float area,perimeter;

cout<<"\nvalue of a ";
cin>>a;
cout<<"value of b ";
cin>>b;

area = a*b;
cout<<"area is "<<area<<endl;

perimeter = 2*(a+b);
cout<<"perimeter is "<<perimeter<<endl;
}
Output:
Task 4:
#include <iostream>
using namespace std;
int main(void)
{
/*using if else statement*/
float F;
float celsius;

cout<<"temp in farenheit ";


cin>>F;

celsius = (F-32)*5/9;
cout<<"Temp in C = "<<celsius<<endl;

}
Output:

You might also like