Question

Q1. Write a C++ program that reads two integers a, and, b on the keyboard to...

Q1. Write a C++ program that reads two integers a, and, b on the keyboard to calculate:

U = (a + b)2 and V = (a - b)2

Q2. Write a C++ program to read a sequence of positive integers and to display the largest integer of that sequence. Use a negative integer to indicate the end of the data entry.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
using namespace std; 
int main() { 
   int a, b, u, v;
   
   cout<<"Enter integer value for a: ";
   cin>>a;
   
   cout<<"Enter integer value for b: ";
   cin>>b;
   
   u = (a+b)*(a+b);
   v = (a-b)*(a-b);
   
   cout<<"U = "<<u<<endl;
   cout<<"V = "<<v<<endl;
   
   return 0; 
}

/////////////////////////////////////////////////////////////////////////////////////

#include <iostream>
using namespace std; 
int main() { 
   double maxNum;
   double x;
   
   cout<<"Enter negative number or zero to stop\n\n";
   
   cout<<"Enter a number: ";
   cin>>x;
   maxNum = x;
   
   while(x > 0){
      cout<<"Enter a number: ";
      cin>>x;
      
      if(x > maxNum){
         maxNum = x;
      }
   }
   
   cout<<"Largest integer: "<<maxNum<<".\n";
   return 0; 
}
Add a comment
Know the answer?
Add Answer to:
Q1. Write a C++ program that reads two integers a, and, b on the keyboard to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT