C++ Basic Programming 7

Question:4
C++ program to calculate and print area and perimeter of square?
Sol:

#include<iostream>
using namespace std;
int main()
{
	int s,a,p;
	cout<<"Enter side of square ";
	cin>>s;
	a=s*s;
	p=4*s;
	cout<<"Area = "<<a<<" Perimeter = "<<p<<endl;
	return(0);
}
/* Output */
Enter side of square 5
Area = 25 Perimeter = 20

Question:5
C++ program to calculate and print area and perimeter of rectangle?
Sol:

#include<iostream>
using namespace std;
int main()
{
	int l,b,a,p;
	cout<<"Enter length and width of rectangle ";
	cin>>l>>b;
	a=l*b;
	p=2*(l+b);
	cout<<"Area = "<<a<<" Perimeter = "<<p<<endl;
	return(0);
}
/* Output */
Enter length and width of rectangle 2
3
Area = 6 Perimeter = 10

Question:6
C++ program to calculate and print area and circumference of a circle?
Sol:

#include<iostream>
using namespace std;
#define pi 3.1415
int main()
{
	float r,a,c;
	cout<<"Enter radius of circle  ";
	cin>>r;
	a=pi*r*r;
	c=2*pi*r;
	cout<<"Area = "<<a<<" Circumferencer = "<<c<<endl;
	return(0);
}
/* Output */
Enter radius of circle  2.3
Area = 16.6185 Circumferencer = 14.4509