Computer Science, asked by omp82846, 7 days ago

WAP to print a value of x ,x = to a*a+b*b/2 in c++​

Answers

Answered by anindyaadhikari13
3

\texttt{\textsf{\large{\underline{Solution}:}}}

The given problem is solved using language - C++.

#include <iostream>

using namespace std;

int main(){

     int a,b;

     double x;

     cout<<"Enter a: ";

     cin>>a;

     cout<<"Enter b: ";

     cin>>b;

     x=(a*a+b*b)/2.0;

     cout<<"The value of x is: "<<x;

     return 0;

}

\texttt{\textsf{\large{\underline{Logic}:}}}

  • Accept first number, say a.
  • Accept second number, say b.
  • Declare and initialize x = (a² + b²)/2.
  • Display the value of x.

See attachment for output.

Attachments:
Similar questions