Portfolio 2 Assignment: Online Shopping Application (10%, due Week 12, Sunday 24 January 11:59pm) Overview This is the first part of the second Portfolio-worth 10% of your final grade for….

## Write a function named .reduoc. that takes two positive integer argumems.

AssignmeM g 3 Max Marks: 30

Question I: DEFINITION: A positive integer d is culled a divisor of an integer n if and oMy if Ne remainder after n is divided hy d zero. In thi.anew e also say that ” divides n , or Nat , is divisible by,. Here are some examples, • divisor of 35 ; that 35 iq divisible by s. .7 is a na a divisor of 27; that is. 27 is not divisible by 7 .1 is a divisor.’ that is. 14 is divisible by I lin fact. 1 is a divisor.’ every (eager ). 1E is a divisor of 0: that i.0 is divisihle hy 12 C and O. one can test the expresOon n 9f, d to determine whether d is a divisor of n The gra. mime rrfmr of a airy integers m ands Ina bah zero) is the largest positive integer d that is a divisor of both rn and n We sometimes use the abbreviation “gad.’ for “greatest comma diisor. Here are sane etunples: 10 is Jamie g.c.d. 40 and 50; IE is the g.c.d. (01 and 432 ; I is the gc.d.o(256 and 625; 6 is the g.c.d. of 6 and .12 32 is the g.c.d. a0 and 3E. Mite a function named ‘g_

QuatIon positive integer n is said to sepia (or, “a p.m”) if and only if n is greater than 1 and is divisible only by 1 and n. For example, the integers 17 and 29 are prime. but 1 and 38 are not pime. Write a function maned Is_prime.thilt takes apoiiihr :sager argument and returns . its vaue the integer 1 if the argument is p.m and returns the integer° othenvbe. Thus, for exam*. °out isprime1191« endl; // will prim 1 °out « is_prizna I I« end,. A, will prim 0 °out « is_prime1511,« end,. /, will prim 0 °out « endl,/ will print 0

Question 3:

Write a function named .reduoc. that takes two positive integer argumems. call Nein union and .denom”. treats them as tile numerator and denominator of a fraction, and reduces the fracion. That is to say. each of the two arguments will he modified by dividing it by the gremest common sor of the two integos. The Ilmetion should MIMI value.° indicate failure to reduce) if eiNer of the two arguments is zero or negative. and shadd mum the value I oNerwise. Thus, for example, if m and n have hem declared to be kteger voiables in a program, Nen m=25; (red • 15; if uce(mAll cum m « « e.;

D DOO O ,–> 1.__I Tools Mobile View Share

0 0

D

PDF to DOC