#include <stdio.h> /* * Asks the user to enter a fraction, and then reducesthe *
ID: 3617222 • Letter: #
Question
#include <stdio.h>/* * Asks the user to enter a fraction, and then reducesthe * fractions to its lowest terms. * Returns the integer results to the caller. */
void get_fraction (int *original_num, int*original_denom);
int get_int();
/* Get a postive integer from the keyboard. */
void reduce(int a, int b,int *newa,int *newb) ; /*Euclids algorithm */
int main()
{ int original_num = 0; int original_denom = 0; int reduced_num = 0; int reduced_denom = 0;
printf ("This program reduces a fraction that youenter "); printf ("to its lowest terms ");
get_fraction(&original_num,&original_denom); reduce(original_num, original_denom,&reduced_num, &reduced_denom); printf ("%d/%d reduced to its lowest terms is%d/%d ",original_num, original_denom, reduced_num,reduced_denom);
return 0; }
void get_fraction (int *original_num, int*original_denom) { printf("Please enter a fraction as two positiveintegers "); printf("Numerator: "); *original_num=get_int(); printf("Denominator: "); *original_denom=get_int(); }
int get_int() { int original_num = 0; char ch; scanf ("%c", &ch); while (ch!=' ') { if(ch<'0'||ch>'9') { printf ("Please enter aninteger greater than 0 "); while (getchar() != ' '); /* Clear keyboard input buffer.*/ original_num=0; } else original_num=original_num*10+(ch-48); scanf ("%c", &ch); } return original_num; }
/* Get a postive integer from the keyboard. */
void reduce(int a, int b,int *newa,int *newb) /*Euclids algorithm */ { *newa=a; *newb=b;
while(a!=b) { if(a>b) a -= b; else b -= a; } *newa=*newa / a; *newb=*newb / a; }
how you make it so that if you input a 123.456 it willreturn it as 123 ? #include <stdio.h>
/* * Asks the user to enter a fraction, and then reducesthe * fractions to its lowest terms. * Returns the integer results to the caller. */
void get_fraction (int *original_num, int*original_denom);
int get_int();
/* Get a postive integer from the keyboard. */
void reduce(int a, int b,int *newa,int *newb) ; /*Euclids algorithm */
int main()
{ int original_num = 0; int original_denom = 0; int reduced_num = 0; int reduced_denom = 0;
printf ("This program reduces a fraction that youenter "); printf ("to its lowest terms ");
get_fraction(&original_num,&original_denom); reduce(original_num, original_denom,&reduced_num, &reduced_denom); printf ("%d/%d reduced to its lowest terms is%d/%d ",original_num, original_denom, reduced_num,reduced_denom);
return 0; }
void get_fraction (int *original_num, int*original_denom) { printf("Please enter a fraction as two positiveintegers "); printf("Numerator: "); *original_num=get_int(); printf("Denominator: "); *original_denom=get_int(); }
int get_int() { int original_num = 0; char ch; scanf ("%c", &ch); while (ch!=' ') { if(ch<'0'||ch>'9') { printf ("Please enter aninteger greater than 0 "); while (getchar() != ' '); /* Clear keyboard input buffer.*/ original_num=0; } else original_num=original_num*10+(ch-48); scanf ("%c", &ch); } return original_num; }
/* Get a postive integer from the keyboard. */
void reduce(int a, int b,int *newa,int *newb) /*Euclids algorithm */ { *newa=a; *newb=b;
while(a!=b) { if(a>b) a -= b; else b -= a; } *newa=*newa / a; *newb=*newb / a; }
how you make it so that if you input a 123.456 it willreturn it as 123 ?
Explanation / Answer
please rate - thanks like this? /* * Asks the user to enter a fraction, and then reduces the * fractions to its lowest terms. * Returns the integer results to the caller. */ void get_fraction (int *original_num, int *original_denom); int get_int(); /* Get a postive integer from the keyboard. */ void reduce(int a, int b,int *newa,int *newb) ; /*Euclids algorithm */ int main() { int original_num = 0; int original_denom = 0; int reduced_num = 0; int reduced_denom = 0; printf ("This program reduces a fraction that youenter "); printf ("to its lowest terms "); get_fraction(&original_num,&original_denom); reduce(original_num, original_denom,&reduced_num, &reduced_denom); printf ("%d/%d reduced to its lowest terms is %d/%d ",original_num, original_denom, reduced_num, reduced_denom); return 0; } void get_fraction (int *original_num, int *original_denom) { printf("Please enter a fraction as two positiveintegers "); printf("Numerator: "); *original_num=get_int(); printf("Denominator: "); *original_denom=get_int(); } int get_int() { int original_num = 0; char ch; scanf ("%c", &ch); while (ch!=' ') { if(ch'9') {if(ch=='.') { while (getchar() != ' '); return original_num; } printf ("Pleaseenter an integer greater than 0 "); while (getchar()!= ' '); /* Clear keyboard input buffer.*/ original_num=0; } else original_num=original_num*10+(ch-48); scanf ("%c", &ch); } return original_num; } /* Get a postive integer from the keyboard. */ void reduce(int a, int b,int *newa,int*newb) /*Euclids algorithm */ { *newa=a; *newb=b; while(a!=b) { if(a>b) a -= b; else b -= a; } *newa=*newa / a; *newb=*newb / a; }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.