Write C++ program that calculates the area and the circumference of a square. Read the
required input from the user at the runtime. Where area = edge2 and circumference = 4 edge
Solution
#include<iostream>
using namespace std;
int main()
{
float length, perimeter;
cout<<"Enter the Length of the Square: ";
cin>>length;
perimeter = 4*length;
cout<<"\nPerimeter = "<<perimeter;
cout<<endl;
return 0;
}
Output (https://www.programiz.com/cpp-programming/online-compiler/) and online compiler
#include<iostream>
using namespace std;
float areaOfSquare(float);
int main()
{
float length, area;
cout<<"Enter the Length of the Square: ";
cin>>length;
area = areaOfSquare(length);
cout<<"\nArea = "<<area;
cout<<endl;
return 0;
}
float areaOfSquare(float length)
{
return (length*length);
}
Output (https://www.programiz.com/cpp-programming/online-compiler/) and online compiler
Comments
Leave a comment