0% found this document useful (0 votes)
22 views

Lecture 8 Coding Questions

Uploaded by

syash9457
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
22 views

Lecture 8 Coding Questions

Uploaded by

syash9457
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 22
‘Question Not ‘single File Programming Question Problem statement sarah is studying number theory ands curious about the sum of avisos of a given number. She wants to write a C++ program to calculate this. Can you help horn witing a program thot takes « positive integer as input an calculates the sum of ts dvsors using @ roference valable? Function Name: void calculateDivisersum Note: This is e'2ample question asked in infosys rerultmant. Input format: The input consists of an integer N Output format : Te output displaye the eum ofall the aivisars of N ‘Output format : The output displays the sum of all the divisors of N. Code constraints : 1<= N= 00 ‘Sample test cases: Input: 5 Whitelist set: ‘Output tices iret emsCnee sy Pesan e eeaa F void calculatepivisorsum(int num, int &sum) { re a irae ee ean ees eg Pec rene ener : 3 raccoons int N; Cea Bae PRE ete Tete neta eect) Coe Se RE el MSU ot Stotue Conect rt bined ft) Hes wes O Trescompled 2 Tnansubrited 1 Lowe Kany Gusten ype Shglaflamogrmming Subject C44 opie Rietone Sub Tope Relweneavaranae Suan teensy crate TD shom eetcase sree (7) Show eoiion est s/s Testooses Passed ‘compiier Messoge tna at cepteseutnt Timotve) Time comploty space Compatty wossage Solution 1 Parra es ers using namespace std; void calculateDivisorsum(int number, int& sum) ( Sec Gi are recon eee eg if (number % i == 0) { Ere ey } i Cran Tv ules at rear ae Peyton tetra strc cout << divisorsum; SSeS ‘ouesionno:2 Single Fle Programming Question sores oma ents ah eso analysts rumba dole tha sum she recent rte rogram ofa hase humus sia funeton eal wm) Teather ‘nroton sve created a progam fa slowshertoiput aca numbers ond amputathari uangine cones eal by Voie hn Sarohuns progre, snes prema art the rumba on by ne tr inpting enue. he progr noes the sunt. tune, th rumba ore oss vive, mecring ht he rg! elves oe nat modded. hs uncon ees og ta povided umber, occuulng em ‘ce me computations cares th rgto dps he sumo th een owing oth toque anaye the et rurale The Cal by Vue approach ensures a the ‘gra rursarsreman unsnanged, proving Saran th acuta rents and gresrng neg thei Sot ‘ote: nis sample question asad in Capgernnieetutner rot tormet ‘eatin helmut cana tne tn ‘Output format: The output prints the sum of elements. ‘Sample test cases: Input: Output: 5 220 “u 36 Input2: output2: e 2046 Pry 456 709 uz 258 369 951 753 Whitelist gd cect eH ae Crees ae cece ey (CCl ae oa totalsum ~ arr[i]; ocr parent cae tae (Coaren aeeaL ae coo ne COneratee 7 Poon ee Coy Cormeen eer ey Fill your code here omen Bc ae Ca ea eS poesia (Ci Oe ae ee Poca cer resctnn pareOnes ae ca Ce (Cri Oe aU Sa ee Shera esh i int result - sum(arr, n); Pov sere sears CH ‘tote caret onsnones Oho ries @ nnwcengi 1 Terie 1 lent Gan Cusine Sngeemepunming Snes Ge erence roe compte enone epi op tte xp Solution 1 PEustreaeserer ts int sum(int a[], int n) { ae ea Ch seat ae aa ae ee ee Sear eae i eee i int main() Ulam cya) oe cae a mee ae mean ae eso eg Be Uesaried Fy i ita = sum(a, n)3 Bee eee eae Eet UT TES Det eatin es ° ‘Single Fle Programming Question obi totement Aes, amat ernst worn rata 9 rogiom that calcustesthepanerataghennumbr Se cede tolmplement futon cae power) ht nk n to parameters th ass ‘umber an tbe poner (p). Heve toe worse ue cay eencs to pero Me caution. ace rapa prompt neuer ener tetas ba nd the poner hy wi olen th np cr prove he power) fcson coe wih the memory eset he base number athe panes. The fuetin prs the pcos cok uations oe update teva the meray aces of tebase nant ie ‘ty, Ale pregrom aplasia of owe nba ia ote power ape ae eters sample question ste roe enutent nputermat: ‘enputconis te bape exponent Input format: The input consists of the base and exponent Output format : The output prints the result. ‘Sample test cases: Input}: 53 whitelist set & ‘Output I: 125 atten Esra tees reg Ss Pen e ee Pn Neue a re ee Piracy on uae ee Mea ch see eeo ng eran ee a Yi LE ee ord y int main () { ial aa Cee em ria Pena Ee ea ou Cor ee Cee ay fo seceneended ering Cota: cue CP. Cal by Rlence Sots Camct Mortctshed Wd Hrtrsad © Tirasconpied 1 Tnernomited 1 ete Mem Gueclntjpe ShglerleReganming Sine! cet Tos Runetane inne caltyitence —ooretanany Apgy 4)e testcase Posse Comper Message cept pt ope Toot) ave Complety space Comenty Message cempoten ecm eet cannes pt ae ° sess = complnteneuceet gta pt thet et Solution! Pst ees Cree ss PE Neuter S oy} Taco Pra a Bc che Uees oat power(b, ©); ey} L void poner(int® b, int& e) { int result - 1; while (e > 0) { ee ee C4 y std::cout << result;

You might also like