Question 2.16

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.2 kB
3
Indexable
Never
// Online C++ compiler to run C++ program online
#include <iostream>

int main() {
    // Write C++ code here
    int numbers [2];
    std::cout << "Please Enter Two Numbers: ";
    for(int i; i<2; i++){
        std::cin >> numbers[i];
    }
    std::cout<<"The two numbers you entered are: ";
    for(int i; i<2; i++){
        std::cout << numbers[i]<< ' ';
    }
     std::cout<<"\n";
    int sum = numbers[0] + numbers[1];
    std::cout << "The sum of the two numbers is : "<< sum <<"\n";
    
    int product = numbers[0]  *  numbers[1];
    std::cout << "The product of the two numbers is : "<< product <<"\n";
    
    int difference = numbers[0] - numbers[1];
    if(difference < 0){
        int difference1 = (-1) * difference;
        std::cout << "The difference of the two numbers is : "<< difference1<<"\n";
    }else{
        std::cout << "The difference of the two numbers is : "<< difference<<"\n";
    }
    
     double quotient1 = static_cast<double>(numbers[0]) / numbers[1];
    double quotient2 = static_cast<double>(numbers[1]) / numbers[0];
    std::cout << "The two quotients for the two numbers is "<< quotient1<<" and  "<<  quotient2;
    
    return 0;
}