Write a program in C++ that stores the numerator and denominator of two numbers infraction, after adding them the result is also stored into fraction format. Use structure fraction to store these numbers and their result (Bothnumeratoranddenominatorshouldbeof type int).
#include <iostream>
struct frac {
int dominator;
int numerator;
double value;
};
int main() {
struct frac frac;
std::cin >> frac.numerator;
std::cin >> frac.dominator;
frac.value = 1.0 * frac.numerator / frac.dominator;
std::cout << frac.value;
}
Comments
Leave a comment