Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program is in the C Programming language. Measure water: Given 2 jugs of ca

ID: 3885715 • Letter: T

Question

This program is in the C Programming language.

Measure water: Given 2 jugs of capacity a and b gallons, and an infinite supply of water, can you fill one of the jugs with exactly c gallons of water? (i) Sample Input: a = 5, b = 3, c = 4 Sample Output: YES (ii) Sample Input: a = 3, b = 6, c = 4 Sample Output: NO

Explanation / Answer

#include #include // function to calculate gcd of two numbers int gcd(int a,int b) { if(a>b) { if(a%b==0) return b; else return gcd(b,a%b); } else { if(b%a==0) return a; else return gcd(a,b%a); } } int main() { int common; int a,b,c; int flag,temp; flag=0; scanf("%d %d %d",&a,&b,&c); if(a a && c > b && flag==0) { printf("NO "); flag=-1; return; } //condition/check 2 if(a == c || b == c && flag==0) { printf("YES "); flag=1; return; } if(c == 0 && flag==0) { printf("YES "); flag=1; return; } common=gcd(a,b); if(c%common==0 && flag==0) printf("YES "); else printf("NO "); return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote