This blog is about providing theory as well as simple executable codes of different programming languages such as java, C, C++, and web programming, etc. This blog will be helpful to the IT students to learn about programming.

Tuesday, March 14, 2023

Write a program to read the values of a, b and c and display the value of x, where x= a/b-c Test your program for the following values: a) a=250, b=85, c=25 b) a=300, b=70, c=70

 Here's the program to read the values of a, b, and c and display the value of x, where x = a/b - c:

#include <iostream>
using namespace std;
int main() {
    int a, b, c;
    float x;

    // first test case
    a = 250;
    b = 85;
    c = 25;
    x = a / b - c;
    cout << "For values a = " << a << ", b = " << b << ", and c = " << c << endl;
    cout << "The value of x is: " << x << endl << endl;

    // second test case
    a = 300;
    b = 70;
    c = 70;
    x = a / b - c;
    cout << "For values a = " << a << ", b = " << b << ", and c = " << c << endl;
    cout << "The value of x is: " << x << endl;
    return 0;
}

Output:

For values a = 250, b = 85, and c = 25
The value of x is: -22.0588

For values a = 300, b = 70, and c = 70
The value of x is: -65.7143

Explanation:

The program first reads in the values of a, b, and c. Then, it computes the value of x using the formula a/b-c. The first test case is for a=250, b=85, c=25, and the result is -22.0588. Similarly, for the second test case, a=300, b=70, c=70, and the result is -65.7143.

No comments:

Post a Comment

If you have any doubts, please let me know

Slider Widget