Posts

Showing posts with the label Cmath

Write a program that prompts the user to enter two points (x1, y1) and (x2, y2) and displays their distance between them.The formula for computing the distance is

Image
(Geometry: distance of two points) Write a program that prompts the user to enter  two points (x1, y1) and (x2, y2) and displays their distance between them.The formula for computing the distance is  √ (x2 - x1)²+ (y2 - y1)² . Note that you  can use pow(a, 0.5) to compute √a.  #Beginner In gcc c++ compiler using namespace std; #include<iostream> #include<cmath> using namespace std; int main() { float x1,y1,x2,y2; cout<< "Enter x1 and y1 :" ; cin>>x1>>y1; cout<< "Enter x2 and y2 :" ; cin>>x2>>y2; float distance=pow((pow(x2-x1,2))+pow(y2-y1,2),0.5); cout<< "The distance between the two points is :" <<distance; return 0; } copy Output Enter x1 and y1 :1 9 Enter x2 and y2 :3 -5 The distance between the two points is :14.1421 [Program finished] Need of Programmer Need of Programmer

Write a program that prompts the user to enter the side of a hexagon and displays its area. The formula for computing the area of a hexagon is

Image
(Geometry: area of a hexagon) Write a program that prompts the user to enter the  side of a hexagon and displays its area. The formula for computing the area of a  hexagon is  Area =(3√3 / 2)s². #Beginner In gcc c++ compiler using namespace std; #include<iostream> #include<cmath> using namespace std; int main() { float side; cout<< "Enter the side :" ; cin>>side; float area=3*sqrt(3)*pow(side,2)/2; cout<< "the area of the hexagon :" <<area; return 0; } copy Output Enter the side :4 the area of the hexagon :41.5692 [Program finished] Need of Programmer Need of Programmer

How cold is it outside? The temperature alone is not enough to provide the answer. Other factors including wind speed, relative humidity, and sunshine play important roles in determining coldness outside. In 2001, the National Weather Service (NWS) implemented the new wind-chill temperature to measure the coldness using temperature and wind speed.

Image
  (Science: wind-chill temperature) How cold is it outside? The temperature alone is  not enough to provide the answer. Other factors including wind speed, relative humidity, and sunshine play important roles in determining coldness outside. In 2001, the National Weather Service (NWS) implemented the new wind-chill temperature to measure the coldness using temperature and wind speed. The formula is: twc = 35.74 + 0.6215ta - 35.75v 0.16 + 0.4275tav 0.16  where ta is the outside temperature measured in degrees Fahrenheit and v is the speed measured in miles per hour. twc is the wind-chill temperature. The formula cannot be used for wind speeds below 2 mph or temperatures below –58°F or above 41°F.  Write a program that prompts the user to enter a temperature between –58°F and  41°F and a wind speed greater than or equal to 2 and displays the wind-chill temperature. Use pow(a, b) to compute v 0.16 #Beginner In gcc c++ compiler using namespace std; #include<io...

Write a program that displays the following table:

Image
(Print a table) Write a program that displays the following table: x        y       pow(x, y) 2.5   1.2    3.00281 5.0   2.4    47.5913 1.2   3.6    1.92776 2.4   5.0    79.6262 3.6   2.5    24.5899 #Beginner In gcc c++ compiler using namespace std; #include<iostream> #include<cmath> using namespace std; int main() { cout<< "x\t" << "y\t" << "pow(x,y)" <<endl; cout<<2.5<< "\t" <<1.2<< "\t" <<pow(2.5,1.2)<<endl; cout<<5.0<< "\t" <<2.4<< "\t" <<pow(5.0,2.4)<<endl; cout<<1.2<< "\t" <<3.6<< "\t" <<pow(1.2,3.6)<<endl; cout<<2.4<< "\t" <<5.0<< "\t" <<pow(2.4,5.0)<<endl; cout<<3.6<< "\t" <<2.5<< "\t" <<pow(3.6,2.5)<<endl; retu...

Write a program that prompts the user to enter three points (x1, y1), (x2, y2), (x3, y3) of a triangle and displays its area. The formula for computing the area of a triangle is

Image
(Geometry: area of a triangle) Write a program that prompts the user to enter three  points (x1, y1), (x2, y2), (x3, y3) of a triangle and displays its area. The formula  for computing the area of a triangle is s = (side1 + side2 + side3)/2; area = 2√ s(s - side1)(s - side2)(s - side3) #Beginner In gcc c++ compiler using namespace std; #include<iostream> #include<cmath> using namespace std; int main() { float x1,y1,x2,y2,x3,y3; cout<< "Enter three point of triangle:" <<endl; cout<< "point1 x1 and y1 :" ; cin>>x1>>y1; cout<< "point2 x2 and y2 :" ; cin>>x2>>y2; cout<< "point3 x3 and y3 :" ; cin>>x3>>y3; float side1=sqrt(pow(x2-x1,2)+pow(y2-y1,2)); float side2=sqrt(pow(x3-x2,2)+pow(y3-y2,2)); float side3=sqrt(pow(x1-x3,2)+pow(y1-y3,2)); float s=(side1+side2+side3)/2; float area=sqrt(s*(s-side1)*(s-side2)*(s-side3)); cout<< "...