Your company has been asked to write a fraction calculator Your group has been a
ID: 3624395 • Letter: Y
Question
Your company has been asked to write a fraction calculator Your group has been assigned the task of simplifying fractions Main Program Design and code a program that simplifies fractions Your program prompts for and accepts the numerator and denominator of a fraction and displays the fraction in simplified form. To calculate the simplified numerator and denominator, your program calls the simplify function described below, The output from your program looks something like Design and code a function named simplify that simplifies the numerator and denominator of a fraction. the function receives the addresses of two int variables. The variables themselves holds the numerator and denominator respectively. The function resets those variables to the simplified numerator and denominator values, if simplification was possible The function docs not return any value itself. the header of your function looks something like: void simplify(int *numerator, int *denominator) Include negative as well as zero values in your test eases. roots Function Design and code a C function named roots that calculates the roots of a quadratic equation. Your function receives three doubles that hold the coefficients of the quadratic equation and returns through two other double parameters the real roots of the equation. The function returns the number of real roots as the return value of the function itself. The header for your function looks something like int roots(double a, double b, double c, doubleExplanation / Answer
Program has 1 file:main.cpp
#include<stdio.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void simplify(int *x,int *y)
{ int a,b;
*x=abs(*x);
*y=abs(*y);
a=*x;
b=*y;
while(a!=b)
{
if (a<b) b=b-a;
else a=a-b;
}
*x=(*x)/a;
*y=(*y)/b;
}
void main()
{
int tu,mau,choice,m=1,n=1;
while(1)
{
system("cls");
printf("choose oneof the following options ");
printf("1. Input fraction ");
printf("2. Simplify fraction ");
printf("3. Display fraction ");
printf("0. Exit ");
printf("your selection (0-->3):");
scanf("%d",&choice);
if(choice==0)
{
printf("Have a nice day!");
break;
}
if(choice==1)
{
printf("Enter numerator: ");
scanf("%d",&tu);
if(tu<0)m=-1;
printf("Enter denominator: ");
scanf("%d",&mau);
if(mau<0)n=-1;
if(mau==0)
{
printf("Invail input.Input again! ");
getch();
}
}
else if(choice==2)
{
if(tu!=0)simplify(&tu,&mau);
}
else if(choice==3)
if(tu!=0)
{
tu*=m*n;
printf("%d/%d ",tu,mau);
}
else printf("0 ");
else
{
printf("**Invail choice.Try again ");
}
printf("Press any key to continue...");
getch();
}
}
#include<stdio.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void simplify(int *x,int *y)
{ int a,b;
*x=abs(*x);
*y=abs(*y);
a=*x;
b=*y;
while(a!=b)
{
if (a<b) b=b-a;
else a=a-b;
}
*x=(*x)/a;
*y=(*y)/b;
}
void main()
{
int tu,mau,choice,m=1,n=1;
while(1)
{
system("cls");
printf("choose oneof the following options ");
printf("1. Input fraction ");
printf("2. Simplify fraction ");
printf("3. Display fraction ");
printf("0. Exit ");
printf("your selection (0-->3):");
scanf("%d",&choice);
if(choice==0)
{
printf("Have a nice day!");
break;
}
if(choice==1)
{
printf("Enter numerator: ");
scanf("%d",&tu);
if(tu<0)m=-1;
printf("Enter denominator: ");
scanf("%d",&mau);
if(mau<0)n=-1;
if(mau==0)
{
printf("Invail input.Input again! ");
getch();
}
}
else if(choice==2)
{
if(tu!=0)simplify(&tu,&mau);
}
else if(choice==3)
if(tu!=0)
{
tu*=m*n;
printf("%d/%d ",tu,mau);
}
else printf("0 ");
else
{
printf("**Invail choice.Try again ");
}
printf("Press any key to continue...");
getch();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.