1"use strict";(self.webpackChunkc_c_notes=self.webpackChunkc_c_notes||[]).push([[8330],{1470:(e,n,t)=>{t.d(n,{A:()=>w});var a=t(8168),i=t(6540),r=t(53),l=t(3104),u=t(6347),s=t(7485),o=t(1682),m=t(9466);function d(e){return function(e){return i.Children.map(e,(e=>{if(!e||(0,i.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad <Tabs> child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`)}))?.filter(Boolean)??[]}(e).map((e=>{let{props:{value:n,label:t,attributes:a,default:i}}=e;return{value:n,label:t,attributes:a,default:i}}))}function c(e){const{values:n,children:t}=e;return(0,i.useMemo)((()=>{const e=n??d(t);return function(e){const n=(0,o.X)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in <Tabs>. Every value needs to be unique.`)}(e),e}),[n,t])}function p(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function g(e){let{queryString:n=!1,groupId:t}=e;const a=(0,u.W6)(),r=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)throw new Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:n,groupId:t});return[(0,s.aZ)(r),(0,i.useCallback)((e=>{if(!r)return;const n=new URLSearchParams(a.location.search);n.set(r,e),a.replace({...a.location,search:n.toString()})}),[r,a])]}function h(e){const{defaultValue:n,queryString:t=!1,groupId:a}=e,r=c(e),[l,u]=(0,i.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(n){if(!p({value:n,tabValues:t}))throw new Error(`Docusaurus error: The <Tabs> has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const a=t.find((e=>e.default))??t[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:n,tabValues:r}))),[s,o]=g({queryString:t,groupId:a}),[d,h]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[a,r]=(0,m.Dv)(t);return[a,(0,i.useCallback)((e=>{t&&r.set(e)}),[t,r])]}({groupId:a}),b=(()=>{const e=s??d;return p({value:e,tabValues:r})?e:null})();(0,i.useLayoutEffect)((()=>{b&&u(b)}),[b]);return{selectedValue:l,selectValue:(0,i.useCallback)((e=>{if(!p({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);u(e),o(e),h(e)}),[o,h,r]),tabValues:r}}var b=t(2303);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function f(e){let{className:n,block:t,selectedValue:u,selectValue:s,tabValues:o}=e;const m=[],{blockElementScrollPositionUntilNextRender:d}=(0,l.a_)(),c=e=>{const n=e.currentTarget,t=m.indexOf(n),a=o[t].value;a!==u&&(d(n),s(a))},p=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=m.indexOf(e.currentTarget)+1;n=m[t]??m[0];break}case"ArrowLeft":{const t=m.indexOf(e.currentTarget)-1;n=m[t]??m[m.length-1];break}}n?.focus()};return i.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":t},n)},o.map((e=>{let{value:n,label:t,attributes:l}=e;return i.createElement("li",(0,a.A)({role:"tab",tabIndex:u===n?0:-1,"aria-selected":u===n,key:n,ref:e=>m.push(e),onKeyDown:p,onClick:c},l,{className:(0,r.A)("tabs__item",y.tabItem,l?.className,{"tabs__item--active":u===n})}),t??n)})))}function v(e){let{lazy:n,children:t,selectedValue:a}=e;const r=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=r.find((e=>e.props.value===a));return e?(0,i.cloneElement)(e,{className:"margin-top--md"}):null}return i.createElement("div",{className:"margin-top--md"},r.map(((e,n)=>(0,i.cloneElement)(e,{key:n,hidden:e.props.value!==a}))))}function x(e){const n=h(e);return i.createElement("div",{className:(0,r.A)("tabs-container",y.tabList)},i.createElement(f,(0,a.A)({},e,n)),i.createElement(v,(0,a.A)({},e,n)))}function w(e){const n=(0,b.A)();return i.createElement(x,(0,a.A)({key:String(n)},e))}},7150:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>C,contentTitle:()=>E,default:()=>_,frontMatter:()=>A,metadata:()=>S,toc:()=>N});var a=t(8168),i=(t(6540),t(5680)),r=t(2355),l=t(1470),u=t(9365);const s='#include <iostream>\n#include <cstdlib>\n#define min 1\n#define max 10\nusing namespace std;\n\nint main() {\n int n;\n\n for (int i = 1; i <= 5;
1 i++) {\n n = rand() % (max - min + 1) + min;\n cout << "Number " << i << " generated: " << n << endl;\n }\n\n return 0;\n}\n',o='#include <iostream>\n#include <cstdlib>\n#include <ctime>\n#define min 1\n#define max 10\nusing namespace std;\n\nint main() {\n\tsrand(time(NULL));\n\n int n;\n\n for (int i = 1; i <= 5; i++) {\n n = rand() % (max - min + 1) + min;\n cout << "Number " << i << " generated: " << n << endl;\n }\n\n return 0;\n}\n',m='#include <iostream>\n#include <cstdlib>\n#include <ctime>\n#define min 1\n#define max 10\nusing namespace std;\n\nint main() {\n srand(time(NULL));\n\n int num1 = rand() % (max - min + 1) + min, \n num2 = rand() % (max - min + 1) + min;\n \n if (num1 > num2) {\n cout << "The number" << num1 << " is the largest" << endl;\n cout << "The number" << num2 << " the smallest" << endl;\n } else if (num1 == num2) {\n cout << "The numbers " << num1 << " and " << num2 << " are equal" << endl;\n } else {\n cout << "The number " << num2 << " is the largest" << endl;\n cout << "The number " << num1 << " the smallest" << endl;\n }\n\n return 0;\n}\n',d='#include <iostream>\n#include <cstdlib>\n#include <ctime>\n#define min 5\n#define max 30\nusing namespace std;\n\nint main() {\n srand(time(NULL));\n\n int num, maximum = 5;\n\n for (int i = 0; i < 10; i++) {\n num = rand() % (max - min + 1) + min;\n\n cout << "Number " << i + 1 << " generated: " << num << endl;\n\n if (num >= maximum)\n maximum = num;\n }\n\n cout << "The maximum number generated is: " << maximum << endl;\n\n return 0;\n}\n',c='#include <iostream>\n#include <cstdlib>\n#include <ctime>\n#define min 0\n#define max 1\nusing namespace std;\n\nint main() {\n srand(time(NULL));\n\n int coinTosses = 3, \n headsCount = 0, \n x;\n\n for (int i = 0; i < coinTosses; i++)\n {\n x = rand() % (max - min + 1) + min;\n if (x == 0)\n {\n cout << "Heads" << endl;\n headsCount++;\n }\n else {\n cout << "Tails" << endl;\n }\n }\n\n cout << "\\nNumber of heads: " << headsCount << endl;\n cout << "Number of tails: " << (coinTosses - headsCount) << endl;\n\n return 0;\n}\n',p='#include <iostream>\n#include <cstdlib>\n#include <ctime>\n#include <cmath>\n#define min 1\n#define max 10\nusing namespace std;\n\nint main() {\n srand(time(NULL));\n\n int a = rand() % (max - min + 1) + min;\n int b = rand() % (max - min + 1) + min;\n int c = rand() % (max - min + 1) + min;\n\n int sum = a + b + c;\n\n cout << "Generated numbers:" << endl << a << endl << b << endl << c << endl;\n cout << "\\nSum: " << sum << endl;\n \n float r = sqrt(sum);\n int rad = r;\n\n if (r == rad)\n cout << "Perfect square." << endl;\n else\n cout << "Not a perfect square." << endl;\n\n return 0;\n}\n',g='#include <iostream>\n#include <cstdlib>\n#include <ctime>\nusing namespace std;\n\nint main() {\n srand(time(NULL));\n\n int n, count = 0;\n\n cout << "How many numbers you want to generate?" << endl;\n cin >> n;\n\n for (int i = 1; i <= n; i++) {\n int val = rand();\n if (val % 3 == 0)\n {\n cout << "Multiple number of 3: " << val << endl;\n count++;\n }\n }\n\n if (count == 0)\n cout << "No multiple number of 3 was generated." << endl;\n else\n cout << count << " numbers multiple of 3 have been generated." << endl;\n \n return 0;\n}\n',h='#include <iostream>\n#include <cstdlib>\n#include <ctime>\n#define min 5\n#define max 30\nusing namespace std;\n\nint main() {\n srand(time(NULL));\n\n int n, sum = 0, count = 0, i;\n float average;\n\n for (i = 0; i < 20; i++) {\n n = rand() % (max - min + 1) + min;\n cout << " Generated number: " << n << endl;\n\n if (n > 20)\n count++;\n\n sum += n;\n }\n\n average = (float)sum / i;\n cout << "\\nAverage: " << average << endl;\n\tcout << "There are "<< count << " numbers greater than 20" << endl;\n\n return 0;\n}\n',b='#include <iostream>\n#include <cstdlib>\n#include <ctime>\n#define min 1\n#define max 6\nusing namespace std;\n\nint main() {\n srand(time(NULL));\n int x, count = 0, y;\n\n cout << "How many times do you want to roll the dice?" << endl;\n cin >> x;\n\n for (int i = 0; i < x;
1 i++) {\n y = rand() % (max - min + 1) + min;\n\n cout << "The extracted number is: " << y << endl;\n\n if (y == 6)\n count++;\n }\n cout << "The number 6 came out " << count << " times." << endl;\n\n return 0;\n}\n',y="#include <iostream>\n#include <cstdlib>\n#include <ctime>\n#define min 65 // see ASCII table\n#define max 90 // see ASCII table\nusing namespace std;\n\nint main() {\n srand(time(NULL));\n char lett1, lett2, lett3;\n\n // a char in C/C++ is already a number (the character's ASCII code) \n // so there's no need to explicitly make a conversion\n lett1 = rand() % (max - min + 1) + min;\n lett2 = rand() % (max - min + 1) + min;\n lett3 = rand() % (max - min + 1) + min;\n\n cout << lett1 << endl;\n cout << lett2 << endl;\n cout << lett3 << endl;\n\n int count = 0;\n\n if (lett1 == 'A' || lett1 == 'E' || lett1 == 'I' || lett1 == 'O' || lett1 == 'U') {\n count++;\n }\n if (lett2 == 'A' || lett2 == 'E' || lett2 == 'I' || lett2 == 'O' || lett2 == 'U') {\n count++;\n }\n if (lett3 == 'A' || lett3 == 'E' || lett3 == 'I' || lett3 == 'O' || lett3 == 'U') {\n count++;\n }\n\n cout << \"There are \" << count << \" vowels among the generated letters\" << endl;\n\n return 0;\n}\n",f='#include <iostream>\n#include <cstdlib>\n#include <ctime>\n#define min 1\n#define max 20\nusing namespace std;\n\nint main() {\n srand(time(NULL));\n\n int attempt, count = 0;\n int n = rand() % (max - min + 1) + min;\n\n cout << "Secret number generated. Now guess it!" << endl;\n\n do {\n cout << "Enter a number from 1 to 20: " << endl;\n cin >> attempt;\n count++;\n\n if (n != attempt && n < attempt)\n cout << "Attempt failed, try with a lower number." << endl;\n else if (n != attempt && n > attempt)\n cout << "Attempt failed, try with a higher number." << endl;\n } while (attempt != n);\n\n cout << "You guessed in " << count << " attempts" << endl;\n\n return 0;\n}\n',v='#include <iostream>\n#include <cstdlib>\n#include <ctime>\n#define min 1\n#define max 10\nusing namespace std;\n\nint main() {\n srand(time(NULL));\n\n int input, attempts = 0, n;\n\n n = rand() % (max - min + 1) + min;\n\n do {\n attempts++;\n\n cout << "Enter a number between 1 and 10:" << endl;\n cin >> input;\n\n if (input == n) {\n cout << "\\nYou won with " << attempts << " attempts." << endl;\n break;\n }\n else if (input < n && attempts < 3)\n cout << "\\nWrong, try again with a larger number." << endl;\n else if (input > n && attempts < 3)\n cout << "\\nWrong, try again with a smaller number." << endl;\n else\n cout << "You have finished the attempts" << endl;\n } while (attempts < 3);\n\n return 0;\n}\n',x='#include <iostream>\n#include <cstdlib>\n#include <ctime>\n#define min 10\n#define max 100\nusing namespace std;\n\nint main() {\n srand(time(NULL));\n\n int num, count = 0;\n\n for (int i = 1; i <= 10; i++) {\n num = rand() % (max - min + 1) + min;\n\n cout << i << " Number generated: " << num << endl;\n\n int countDividers = 0;\n\n for (int j = 1; j <= num; j++)\n if (num % j == 0)\n countDividers++;\n \n if (countDividers == 2)\n count++;\n }\n\n cout << count << " prime numbers have been generated." << endl;\n\n return 0;\n}\n',w='#include <iostream>\n#include <cstdlib>\n#include <ctime>\n#define min 10\n#define max 100\nusing namespace std;\n\nint main() {\n srand(time(NULL));\n\n int num, count = 0;\n \n for (int i = 1; i <= 10; i++) {\n num = rand() % (max - min + 1) + min;\n \n cout << i << " Number generated: " << num << endl;\n \n bool prime = true;\n \n for (int j = 2; j < num; j++)\n if (num % j == 0)\n prime = false;\n \n if (prime)\n count++;\n }\n\n cout << count << " prime numbers have been generated." << endl;\n\n return 0;\n}\n',T='#include <iostream>\n#include <cstdlib>\n#include <ctime>\n#define min 10\n#define max 50\nusing namespace std;\n\nint main() {\n srand(time(NULL));\n\n int num = rand() % (max - min + 1) + min;\n cout << "Generated number: " << num << endl;\n\n for (int i = 1; i <= num; i++) { // you can\'t start from 0!\n if (num % i == 0) {\n cout << i << " is a divider of " << num << endl;\n }\n }\n\n return 0;\n}\n',A={sidebar_position:16,id:"exercises_2",title:"Exercises (Part 2)",hide_title:!1,hide_table_of_contents:!1,sidebar_label:"EXERCISES",de
1scription:"Exercises.",slug:"/cpp/exercises_2",custom_edit_url:null},E=void 0,S={unversionedId:"cpp/exercises_2",id:"cpp/exercises_2",title:"Exercises (Part 2)",description:"Exercises.",source:"@site/docs/cpp/EXERCISES_2.md",sourceDirName:"cpp",slug:"/cpp/exercises_2",permalink:"/docs/cpp/exercises_2",draft:!1,editUrl:null,tags:[],version:"current",lastUpdatedAt:1747598548,formattedLastUpdatedAt:"May 18, 2025",sidebarPosition:16,frontMatter:{sidebar_position:16,id:"exercises_2",title:"Exercises (Part 2)",hide_title:!1,hide_table_of_contents:!1,sidebar_label:"EXERCISES",description:"Exercises.",slug:"/cpp/exercises_2",custom_edit_url:null},sidebar:"tutorialSidebar",previous:{title:"Random numbers",permalink:"/docs/cpp/random"},next:{title:"Functions",permalink:"/docs/cpp/functions/"}},C={},N=[{value:"Pseudorandom number generation (\u2605\u2606\u2606)",id:"pseudorandom-number-generation-",level:3},{value:"Greatest and smallest number (\u2605\u2606\u2606)",id:"greatest-and-smallest-number-",level:3},{value:"Greatest number (\u2605\u2606\u2606)",id:"greatest-number-",level:3},{value:"Heads or tails (\u2605\u2606\u2606)",id:"heads-or-tails-",level:3},{value:"Perfect square (\u2605\u2606\u2606)",id:"perfect-square-",level:3},{value:"Count multiples (\u2605\u2606\u2606)",id:"count-multiples-",level:3},{value:"Random average (\u2605\u2606\u2606)",id:"random-average-",level:3},{value:"Dice roll (\u2605\u2606\u2606)",id:"dice-roll-",level:3},{value:"Vowels counter (\u2605\u2605\u2606)",id:"vowels-counter-",level:3},{value:"Guess the number (\u2605\u2606\u2606)",id:"guess-the-number-",level:3},{value:"Prime numbers (\u2605\u2605\u2606)",id:"prime-numbers-",level:3},{value:"Dividers (\u2605\u2605\u2606)",id:"dividers-",level:3}],k={toc:N},I="wrapper";function _(e){let{components:n,...t}=e;return(0,i.yg)(I,(0,a.A)({},k,t,{components:n,mdxType:"MDXLayout"}),(0,i.yg)("p",null,"Now that you know the theory, it's time for some practice!"),(0,i.yg)("p",null,"In this section you'll find a collection of exercises on what we have done since the last training (the generation of random numbers with C++). For each exercise one or multiple solutions are provided, but try to make the program yourself first. Sometimes there will be and hint to help you if you are struggling."),(0,i.yg)("p",null,"For simplicity, we will (almost always) assume for these exercises that the input of the user is valid. If you want to handle the case of invalid inputs, you may want to use a do-while loop. Also, all exercises (except for the first) require the use of dynamic random numbers generation (using ",(0,i.yg)("inlineCode",{parentName:"p"},"srand()"),"), so avoid static generation."),(0,i.yg)("p",null,"A difficulty is assigned to each exercise using a 3-star rating. The difficulty is calibrated for beginners. Keep in mind that it is a subjective parameter, therefore may not be accurate."),(0,i.yg)("h3",{id:"pseudorandom-number-generation-"},"Pseudorandom number generation (\u2605\u2606\u2606)"),(0,i.yg)("p",null,"Write a program to generate 5 random numbers between 1 and 10 statically, then convert the program to use the ",(0,i.yg)("inlineCode",{parentName:"p"},"srand()")," function, generating dynamic random numbers."),(0,i.yg)("details",null,(0,i.yg)("summary",null,"Show solution(s)"),(0,i.yg)(l.A,{mdxType:"Tabs"},(0,i.yg)(u.A,{value:"s1",label:"Solution 1",mdxType:"TabItem"},(0,i.yg)(r.A,{language:"cpp",title:"prng-static.cpp",mdxType:"CodeBlock"},s)),(0,i.yg)(u.A,{value:"s2",label:"Solution 2",mdxType:"TabItem"},(0,i.yg)(r.A,{language:"cpp",title:"prng-dynamic.cpp",mdxType:"CodeBlock"},o)))),(0,i.yg)("h3",{id:"greatest-and-smallest-number-"},"Greatest and smallest number (\u2605\u2606\u2606)"),(0,i.yg)("p",null,"Write a program that generates dynamically two numbers, then prints out what is the greatest and smallest of the two."),(0,i.yg)("details",null,(0,i.yg)("summary",null,"Show solution(s)"),(0,i.yg)(r.A,{language:"cpp",title:"greatest-and-smallest-number.cpp",mdxType:"CodeBlock"},m)),(0,i.yg)("h3",{id:"greatest-number-"},"Greatest number (\u2605\u2606\u2606)"),(0,i.yg)("p",null,"Write a program that generates 10 random numbers between 5 and 30, then determines the greatest among them."),(0,i.yg)("details",null,(0,i.yg)("summary",null,"Show solution(s)"),(0,i.yg)(r.A,{language:"cpp",title:"greatest-number.cpp",mdxType:"C
1odeBlock"},d)),(0,i.yg)("h3",{id:"heads-or-tails-"},"Heads or tails (\u2605\u2606\u2606)"),(0,i.yg)("p",null,"Write a program that simulates the toss of 3 coins, prints out the results and counts how many heads and tails came out."),(0,i.yg)("details",null,(0,i.yg)("summary",null,"Show solution(s)"),(0,i.yg)(r.A,{language:"cpp",title:"head-or-tails.cpp",mdxType:"CodeBlock"},c)),(0,i.yg)("h3",{id:"perfect-square-"},"Perfect square (\u2605\u2606\u2606)"),(0,i.yg)("p",null,"Write a program that generates 3 positive random numbers between 1 and 10 (extremes included), then prints out whether their sum is a perfect square or not."),(0,i.yg)("details",null,(0,i.yg)("summary",null,"Show solution(s)"),(0,i.yg)(r.A,{language:"cpp",title:"perfect-square.cpp",mdxType:"CodeBlock"},p)),(0,i.yg)("h3",{id:"count-multiples-"},"Count multiples (\u2605\u2606\u2606)"),(0,i.yg)("p",null,"Write a program that generates ",(0,i.yg)("em",{parentName:"p"},"n")," positive random numbers (let the user choose ",(0,i.yg)("em",{parentName:"p"},"n"),") in a non-specified range and counts how many numbers are multiples of 3, printing them on the console."),(0,i.yg)("details",null,(0,i.yg)("summary",null,"Show solution(s)"),(0,i.yg)(r.A,{language:"cpp",title:"count-multiples.cpp",mdxType:"CodeBlock"},g)),(0,i.yg)("h3",{id:"random-average-"},"Random average (\u2605\u2606\u2606)"),(0,i.yg)("p",null,"Write a program that generates 20 random numbers in the interval ","[5, 30]",", calculates the average and counts how how many numbers are greater than 20, printing all information on the console."),(0,i.yg)("details",null,(0,i.yg)("summary",null,"Show solution(s)"),(0,i.yg)(r.A,{language:"cpp",title:"rand-average.cpp",mdxType:"CodeBlock"},h)),(0,i.yg)("h3",{id:"dice-roll-"},"Dice roll (\u2605\u2606\u2606)"),(0,i.yg)("p",null,"Write a program that simulates the roll of a six-sided dice (where each side has a unique number) for ",(0,i.yg)("em",{parentName:"p"},"n")," times, showing the results and how many times the number 6 came out."),(0,i.yg)("details",null,(0,i.yg)("summary",null,"Show solution(s)"),(0,i.yg)(r.A,{language:"cpp",title:"dice-roll.cpp",mdxType:"CodeBlock"},b)),(0,i.yg)("h3",{id:"vowels-counter-"},"Vowels counter (\u2605\u2605\u2606)"),(0,i.yg)("p",null,"Write a program that generates 3 uppercase characters of the English alphabet and prints how many of these characters are vowels on the terminal."),(0,i.yg)("details",null,(0,i.yg)("summary",null,"Show solution(s)"),(0,i.yg)(r.A,{language:"cpp",title:"vowels-counter.cpp",mdxType:"CodeBlock"},y)),(0,i.yg)("h3",{id:"guess-the-number-"},"Guess the number (\u2605\u2606\u2606)"),(0,i.yg)("p",null,"Write a program to generate a random number between 1 and 20 that the user has to guess. Give the user some hints after their attempts, revealing if the generated number is greater or smaller than the one entered on the console. Write a variation of the program where there are only 3 attempts to guess the number, but reduce the range to ","[1, 10]","."),(0,i.yg)("details",null,(0,i.yg)("summary",null,"Show solution(s)"),(0,i.yg)(l.A,{mdxType:"Tabs"},(0,i.yg)(u.A,{value:"s1",label:"Solution 1",mdxType:"TabItem"},(0,i.yg)(r.A,{language:"cpp",title:"guess-the-number.cpp",mdxType:"CodeBlock"},f)),(0,i.yg)(u.A,{value:"s2",label:"Solution 2",mdxType:"TabItem"},(0,i.yg)(r.A,{language:"cpp",title:"guess-the-number-with-n-attempts.cpp",mdxType:"CodeBlock"},v)))),(0,i.yg)("h3",{id:"prime-numbers-"},"Prime numbers (\u2605\u2605\u2606)"),(0,i.yg)("p",null,"Write a program that generates 10 numbers in the interval ","[10, 100]"," (extremes included) then counts how many prime numbers have been generated."),(0,i.yg)("details",null,(0,i.yg)("summary",null,"Show solution(s)"),(0,i.yg)(l.A,{mdxType:"Tabs"},(0,i.yg)(u.A,{value:"s1",label:"Solution 1",mdxType:"TabItem"},(0,i.yg)(r.A,{language:"cpp",title:"prime-numbers.cpp",mdxType:"CodeBlock"},x)),(0,i.yg)(u.A,{value:"s2",label:"Solution 2",mdxType:"TabItem"},(0,i.yg)(r.A,{language:"cpp",title:"prime-numbers-with-bool.cpp",mdxType:"CodeBlock"},w)))),(0,i.yg)("h3",{id:"dividers-"},"Dividers (\u2605\u2605\u2606)"),(0,i.yg)("p",null,"Write a program that generates 10 numbers in the interval ","[10, 50]"," (extremes included) then prints out all the dividers (those without the remainder) of the generated number."),(0,i.yg)("details",null,(0,i.yg)("summary",null,"Show solution(s)"),(0,i.yg)(r.A,{language:"cpp",title:"dividers.cpp",mdxType:"C
1odeBlock"},T)))}_.isMDXComponent=!0},9365:(e,n,t)=>{t.d(n,{A:()=>l});var a=t(6540),i=t(53);const r={tabItem:"tabItem_Ymn6"};function l(e){let{children:n,hidden:t,className:l}=e;return a.createElement("div",{role:"tabpanel",className:(0,i.A)(r.tabItem,l),hidden:t},n)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.