├── q1 ├── q2 ├── insert ├── twoSum ├── age-calc ├── isNormal ├── primers ├── subsets ├── swapper ├── vectors ├── vectorss ├── add_element ├── beanArray ├── bean_arrays ├── calculator ├── countDigits ├── fill_array ├── gusingGame ├── hypothenus ├── magic_array ├── minmum_max ├── numberTypes ├── palindrome ├── space-count ├── airplan_seats ├── centeredArray ├── diffrence-sum ├── diffrence_sum ├── evenNumberSum ├── guesing-gmae ├── prime_product ├── sphereVolume ├── complete_array ├── first_lastname ├── hypothenusRule ├── isNormal_number ├── minimum-distance ├── oddvalent_arrays ├── quadraticRoots ├── raindrops-sound ├── reverse-number ├── reverse-string ├── sumPrimeNumbers ├── duplicate-numbers ├── ntth-prime-number ├── RectangleAreaPermeter ├── alpha-numeric-check ├── getMaximum-sub-array ├── read_compute_numbers ├── diffrence-odd-even-numbers ├── quoatientRemainserGetter ├── q1.cpp ├── main.cpp ├── first_lastname.cpp ├── age-calc.cpp ├── diffrence-odd-even-numbers.cpp ├── hypothenus.cpp ├── alpha-numeric-check.cpp ├── twoSum.cpp ├── diffrence_sum.cpp ├── quadraticRoots.cpp ├── reverse-string.cpp ├── sphereVolume.cpp ├── reverse-number.cpp ├── vectorss.cpp ├── RectangleAreaPermeter.cpp ├── quoatientRemainserGetter.cpp ├── raindrops-sound.cpp ├── numberTypes.cpp ├── space-count.cpp ├── swapper.cpp ├── isNormal.cpp ├── hypothenusRule.cpp ├── beanArray.cpp ├── palindrome.cpp ├── isNormal_number.cpp ├── read_compute_numbers.cpp ├── minmum_max.cpp ├── countDigits.cpp ├── add_element.cpp ├── evenNumberSum.cpp ├── primers.cpp ├── sumPrimeNumbers.cpp ├── subsets.cpp ├── ntth-prime-number.cpp ├── oddvalent_arrays.cpp ├── duplicate-numbers.cpp ├── prime_product.cpp ├── insert.cpp ├── bean_arrays.cpp ├── centeredArray.cpp ├── fill_array.cpp ├── magic_array.cpp ├── q2.cpp ├── minimum-distance.cpp ├── calculator.cpp ├── complete_array.cpp ├── gusingGame.cpp └── guesing-gmae.cpp /q1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/q1 -------------------------------------------------------------------------------- /q2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/q2 -------------------------------------------------------------------------------- /insert: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/insert -------------------------------------------------------------------------------- /twoSum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/twoSum -------------------------------------------------------------------------------- /age-calc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/age-calc -------------------------------------------------------------------------------- /isNormal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/isNormal -------------------------------------------------------------------------------- /primers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/primers -------------------------------------------------------------------------------- /subsets: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/subsets -------------------------------------------------------------------------------- /swapper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/swapper -------------------------------------------------------------------------------- /vectors: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/vectors -------------------------------------------------------------------------------- /vectorss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/vectorss -------------------------------------------------------------------------------- /add_element: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/add_element -------------------------------------------------------------------------------- /beanArray: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/beanArray -------------------------------------------------------------------------------- /bean_arrays: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/bean_arrays -------------------------------------------------------------------------------- /calculator: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/calculator -------------------------------------------------------------------------------- /countDigits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/countDigits -------------------------------------------------------------------------------- /fill_array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/fill_array -------------------------------------------------------------------------------- /gusingGame: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/gusingGame -------------------------------------------------------------------------------- /hypothenus: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/hypothenus -------------------------------------------------------------------------------- /magic_array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/magic_array -------------------------------------------------------------------------------- /minmum_max: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/minmum_max -------------------------------------------------------------------------------- /numberTypes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/numberTypes -------------------------------------------------------------------------------- /palindrome: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/palindrome -------------------------------------------------------------------------------- /space-count: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/space-count -------------------------------------------------------------------------------- /airplan_seats: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/airplan_seats -------------------------------------------------------------------------------- /centeredArray: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/centeredArray -------------------------------------------------------------------------------- /diffrence-sum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/diffrence-sum -------------------------------------------------------------------------------- /diffrence_sum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/diffrence_sum -------------------------------------------------------------------------------- /evenNumberSum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/evenNumberSum -------------------------------------------------------------------------------- /guesing-gmae: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/guesing-gmae -------------------------------------------------------------------------------- /prime_product: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/prime_product -------------------------------------------------------------------------------- /sphereVolume: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/sphereVolume -------------------------------------------------------------------------------- /complete_array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/complete_array -------------------------------------------------------------------------------- /first_lastname: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/first_lastname -------------------------------------------------------------------------------- /hypothenusRule: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/hypothenusRule -------------------------------------------------------------------------------- /isNormal_number: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/isNormal_number -------------------------------------------------------------------------------- /minimum-distance: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/minimum-distance -------------------------------------------------------------------------------- /oddvalent_arrays: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/oddvalent_arrays -------------------------------------------------------------------------------- /quadraticRoots: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/quadraticRoots -------------------------------------------------------------------------------- /raindrops-sound: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/raindrops-sound -------------------------------------------------------------------------------- /reverse-number: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/reverse-number -------------------------------------------------------------------------------- /reverse-string: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/reverse-string -------------------------------------------------------------------------------- /sumPrimeNumbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/sumPrimeNumbers -------------------------------------------------------------------------------- /duplicate-numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/duplicate-numbers -------------------------------------------------------------------------------- /ntth-prime-number: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/ntth-prime-number -------------------------------------------------------------------------------- /RectangleAreaPermeter: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/RectangleAreaPermeter -------------------------------------------------------------------------------- /alpha-numeric-check: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/alpha-numeric-check -------------------------------------------------------------------------------- /getMaximum-sub-array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/getMaximum-sub-array -------------------------------------------------------------------------------- /read_compute_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/read_compute_numbers -------------------------------------------------------------------------------- /diffrence-odd-even-numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/diffrence-odd-even-numbers -------------------------------------------------------------------------------- /quoatientRemainserGetter: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RCA-CP-ENGINEERS/RCA_class_problems-2022/HEAD/quoatientRemainserGetter -------------------------------------------------------------------------------- /q1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int val; 6 | string result; 7 | cout<< "Enter marks : "; 8 | cin>>val; 9 | result = val >= 20 ? "passed " : "failed"; 10 | cout << result < 2 | // #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | // unordered_map romans; 8 | // romans["I"] = 1; 9 | // romans["II"] = 2; 10 | // romans["III"] = 3; 11 | // romans["V"] = 5; 12 | return 0; 13 | } -------------------------------------------------------------------------------- /first_lastname.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | void print(string last, string first){ 6 | cout << " Name in reverse is : " << last << " " << first <> first >> last; 12 | print(last, first); 13 | 14 | } -------------------------------------------------------------------------------- /age-calc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int calculateAge(int secs){ 5 | int day_secs = 24 * 3600; 6 | int days_in_secs = secs / day_secs; 7 | cout << " Jhon is " << days_in_secs / 365 << " years old"; 8 | 9 | } 10 | int main(){ 11 | int secs; 12 | cin >> secs; 13 | calculateAge(secs); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /diffrence-odd-even-numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef vector vi; 4 | int getDiffrence(int number[]){ 5 | cout << sizeof(numer); 6 | cout 7 | return sizeof(number) / sizeof(number[0]); 8 | } 9 | 10 | int main(){ 11 | int numbers[4] = {1,2,3,6}; 12 | cout << getDiffrence(numbers); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /hypothenus.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int hypo; 6 | int b; 7 | int a; 8 | cout << "enter numbers a and b" << endl; 9 | cin >> a; 10 | cin >> b; 11 | 12 | hypo = sqrt(pow(a, 2) + pow(b, 2)); 13 | cout << " The squareroot between " << a << " and " << b << " is " << hypo < 2 | using namespace std; 3 | 4 | string getType(int num){ 5 | if(isalnum(num)){ 6 | return " alphanumeric"; 7 | }else{ 8 | return " not alphanumeric "; 9 | } 10 | 11 | } 12 | int main() 13 | { 14 | 15 | int num; 16 | cin >> num; 17 | cout << num << " is " << getType(num) < 2 | using namespace std; 3 | 4 | namespace calculator 5 | { 6 | int add(int a, int b){ 7 | return a + b; 8 | } 9 | } 10 | 11 | 12 | int main(){ 13 | int a ,b; 14 | char comma; 15 | cout << "enter two numbers inform a,b" <> a >> comma >> b; 17 | cout << " answer is : " << calculator::add(a,b) < 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int limit = 9; 8 | int i = 1; 9 | int sum = 0; 10 | int sumSquare = 0; 11 | while (i < limit) 12 | { 13 | sum += i; 14 | sumSquare += pow(i, 2); 15 | i++; 16 | } 17 | 18 | cout << " diffrence " << sumSquare - sum; 19 | 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /quadraticRoots.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int x; 7 | int b; 8 | int a; 9 | int c; 10 | cout << "Enter values for a , b and c" << endl; 11 | cin >> a; 12 | cin >> b; 13 | cin >> c; 14 | 15 | int delta = sqrt(pow(b,2) - (4 * a * c)); 16 | x = (b + delta )/ 2 * a; 17 | cout << " x : " << x; 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /reverse-string.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | void reverse(string text){ 6 | string reversed; 7 | int i; 8 | for(i = text.size(); i > 0; i--){ 9 | cout << text[i]; 10 | } 11 | 12 | 13 | } 14 | int main(){ 15 | 16 | string input; 17 | cin >> input; 18 | 19 | cout << "revesed " < 2 | using namespace std; 3 | 4 | #define PI 3.14; 5 | namespace calculator{ 6 | 7 | int getvolume(int radius){ 8 | return 3.14 * 4 * pow(radius, 3)/ 3; 9 | 10 | } 11 | } 12 | int main(){ 13 | int radius; 14 | cout << "Enter the radius " <> radius; 16 | cout << "Volume " << calculator::getvolume(radius); 17 | 18 | return 0; 19 | 20 | } -------------------------------------------------------------------------------- /reverse-number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int reverse(int n){ 6 | int reverse = 0; 7 | int rem; 8 | 9 | while (n != 0) 10 | { 11 | rem = n % 10; 12 | reverse = reverse * 10 + rem; 13 | n /= 10; 14 | } 15 | return reverse; 16 | } 17 | int main(){ 18 | int n; 19 | cin >> n; 20 | cout << " reversed " << reverse(n); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /vectorss.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | int main(){ 5 | int n; 6 | string name; 7 | vector number{34,45,56,6756,}; 8 | vector names{"main", "hello world", "big"}; 9 | 10 | for(int i = 0; i< number.size(); i++){ 11 | cout << " number " << number[i]; 12 | } 13 | 14 | for(int j = 0; j < names.size(); j++){ 15 | cout << " names " << names[j]; 16 | } 17 | return 0; 18 | } -------------------------------------------------------------------------------- /RectangleAreaPermeter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | namespace rectangle{ 5 | 6 | int area(int wid, int hei){ 7 | return wid * hei; 8 | } 9 | int perimeter(int wid, int hei){ 10 | return (wid + hei) * 2; 11 | } 12 | } 13 | 14 | int main(){ 15 | 16 | int a , b; 17 | cin >> a >> b; 18 | cout << "area : " << rectangle::area(a,b) < 2 | using namespace std; 3 | 4 | int solve(int n1, int n2){ 5 | int remainder = n1 % n2; 6 | float quotient = n1 / n2; 7 | cout << " remainder between " << n1 << " and " << n2 << " is : " << remainder <> a >> b; 14 | solve(a,b); 15 | 16 | return 0; 17 | 18 | } -------------------------------------------------------------------------------- /raindrops-sound.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | string print_sound(int number){ 5 | if(number % 3 == 0 ){ 6 | return "Pling"; 7 | }else if(number % 5 == 0){ 8 | return "Plang"; 9 | }else if(number % 7 == 0){ 10 | return "Plong"; 11 | }else{ 12 | cout << number <> num; 18 | cout < 2 | using namespace std; 3 | 4 | // auth valens 5 | 6 | void check(int number) 7 | { 8 | if (number > 0) 9 | { 10 | cout << " positive " << endl; 11 | } 12 | else if (number < 0) 13 | { 14 | cout << " negative " << endl; 15 | } 16 | else 17 | { 18 | cout << " number is zero " << endl; 19 | } 20 | } 21 | int main() 22 | { 23 | int a; 24 | cin >> a; 25 | check(a); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /space-count.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int cheeckspaces(string text) 5 | { 6 | int count = 0; 7 | string x = ""; 8 | for (int i = 0; i < text.size(); i++) 9 | { 10 | if ( text[i] == ' ') 11 | { 12 | count = count + 1; 13 | } 14 | } 15 | 16 | return count; 17 | } 18 | int main() 19 | { 20 | 21 | string text; 22 | getline(cin, text); 23 | cout << text << " has " << cheeckspaces(text) << " spaces " << endl; 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /swapper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | namespace swapper 5 | { 6 | int swap(int a, int b) 7 | { 8 | int temp; 9 | temp = a; 10 | a = b; 11 | b = temp; 12 | cout << "after swapping a is : " << a << " and b is " << b << endl; 13 | } 14 | } 15 | 16 | int main() 17 | { 18 | int a, b; 19 | char comma; 20 | cout << "enter two numbers inform a,b" << endl; 21 | cin >> a >> comma >> b; 22 | cout << " answer is : " << swapper::swap(a, b) << endl; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /isNormal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int isNormal(int n){ 6 | int count = 2; 7 | while(count>n; 28 | cout< 2 | using namespace std; 3 | 4 | /* 5 | @author valens 6 | 7 | */ 8 | int getSquare(int a, int b){ 9 | int square = sqrt( pow(a, 2) + pow(b, 2)); 10 | return square; 11 | } 12 | 13 | int hypothenus; 14 | int main(){ 15 | for(int i = 1; i < 100; i++){ 16 | for(int j = i; j < 100; j++){ 17 | hypothenus = getSquare(i, j); 18 | if(pow(hypothenus, 2) - pow(i,2) == pow(j,2)){ 19 | cout << "(" << i << "," << j << ")" < 2 | using namespace std; 3 | 4 | bool isBinary(vector arr , int len){ 5 | int first = 0; 6 | int last = len; 7 | int i , j= 0; 8 | for( i = 0 ; i < len ; i++){ 9 | for(j = len ; j > 0 ; j--){ 10 | if(arr[i] == arr[j] + 1 || arr[i] == arr[j] - 1){ 11 | return true; 12 | }else{ 13 | return false; 14 | 15 | } 16 | } 17 | } 18 | } 19 | 20 | int main(){ 21 | vector numbers { 44,44,45,34}; 22 | cout << "result : " << isBinary(numbers, 4) < 2 | using namespace std; 3 | typedef vector vi; 4 | 5 | 6 | void check(string text){ 7 | string left; 8 | int len = text.length(); 9 | int i; 10 | int j; 11 | for( j = len; j >= 0; j--){ 12 | left += text[j]; 13 | } 14 | 15 | if(text.length() == left.length()){ 16 | cout << "palindrome" < 2 | using namespace std; 3 | typedef vector vi; 4 | 5 | int isNormal(int number) 6 | { 7 | int checkNormal = 1; 8 | for (int i = 1; i <= number; i++) 9 | { 10 | if ((number % i) == 0) 11 | { 12 | 13 | if (i % 2 == 0) 14 | { 15 | checkNormal = 1; 16 | } 17 | else 18 | { 19 | checkNormal = 0; 20 | break; 21 | } 22 | } 23 | } 24 | return checkNormal; 25 | } 26 | 27 | int main() 28 | { 29 | 30 | int number = 2; 31 | cout << isNormal(number); 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /read_compute_numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef vector vi; 4 | 5 | void sort(vi arr){ 6 | 7 | int i ; 8 | int len = arr.size(); 9 | for(int i = 1; i < len; i++){ 10 | int position = i; 11 | int current = arr[i]; 12 | while(position > 0 && arr[position- 1 ] > current){ 13 | arr[position] = arr[position- 1]; 14 | position--; 15 | } 16 | arr[position] = current; 17 | 18 | } 19 | for(int j = 0; j < len; j++){ 20 | cout << arr[j] < 2 | using namespace std; 3 | 4 | int getmin(int arr[10]) 5 | { 6 | int min = arr[0]; 7 | for (int i = 0; i < 10; i++) 8 | { 9 | if(arr[i] < min){ 10 | min = arr[i]; 11 | } 12 | } 13 | return min; 14 | } 15 | void mimmax(int arr[10]) 16 | { 17 | int i = 0; 18 | int max = 0; 19 | int min = getmin(arr); 20 | for (int i = 0; i < 10; i++) 21 | { 22 | if (arr[i] > max) 23 | { 24 | max = arr[i]; 25 | } 26 | } 27 | 28 | cout << " max " << max << " min " << min << endl; 29 | } 30 | int main() 31 | { 32 | 33 | int arr[10] = {14, 3, 7, 6, 41, 56, 11, 25, 9, 10}; 34 | mimmax(arr); 35 | return 0; 36 | } -------------------------------------------------------------------------------- /countDigits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int getCount(string num, int target) 5 | { 6 | int count = 0; 7 | int i; 8 | int len = num.size(); 9 | for (i = 0; i < len; i++) 10 | { 11 | 12 | if (num[i] == target) 13 | { 14 | count += 1; 15 | } 16 | else 17 | { 18 | continue; 19 | } 20 | } 21 | 22 | return count; 23 | } 24 | int main() 25 | { 26 | 27 | string num_str; 28 | int num, target; 29 | cin >> num; 30 | cout << " target : " << endl; 31 | cin >> target; 32 | num_str = to_string(num); 33 | cout << target << " found in " << getCount(num_str, target) << " times in " << num << endl; 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /add_element.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void insert(int arr[], int eleme, int pos, int len) 5 | { 6 | int i = len; 7 | while (i < pos) 8 | { 9 | arr[i] = arr[i-1]; 10 | i--; 11 | } 12 | arr[pos] = eleme; 13 | 14 | for (int i = 0; i < len + 1; i++) 15 | { 16 | cout << arr[i] << endl; 17 | } 18 | } 19 | 20 | void deleteEleme(int arr[], int elem, int len){ 21 | int i = 0; 22 | while(i < len){ 23 | if(arr[i] == elem){ 24 | arr[i] = arr[i+1]; 25 | } 26 | i++; 27 | } 28 | for(int i = 0; i < len; i++){ 29 | cout << arr[i] << endl; 30 | } 31 | } 32 | int main() 33 | { 34 | int numbers[5] = {2, 3, 4, 5, 6}; 35 | // insert(numbers, 10, 3, 5); 36 | deleteEleme(numbers, 2, 5); 37 | 38 | // 3 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /evenNumberSum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void getSum(int limit) 6 | { 7 | int i; 8 | int sum = 0; 9 | for (i = 1; i < limit; i++) 10 | { 11 | if (i % 2 == 0) 12 | { 13 | sum += i; 14 | } 15 | } 16 | cout << "sum of numbers less than " << limit << " is : " << sum << endl; 17 | } 18 | 19 | void product(int limit) 20 | { 21 | int i; 22 | int sum = 1; 23 | for (i = 1; i < limit; i++) 24 | { 25 | if (i % 2 == 0) 26 | { 27 | sum = sum * i; 28 | } 29 | } 30 | cout << "product of numbers less than " << limit << " is : " << sum << endl; 31 | } 32 | 33 | 34 | int main() 35 | { 36 | int number; 37 | cin >> number; 38 | cout << "number " << number << endl; 39 | getSum(number); 40 | product(number); 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /primers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int getIndex(vector factors, int target) 5 | { 6 | for (int i = 0; i < factors.size(); i++) 7 | { 8 | if (factors[i] == target) 9 | { 10 | return i + 1; 11 | } 12 | } 13 | } 14 | int main() 15 | { 16 | 17 | vector primes; 18 | int number = 4; 19 | cin >> number; 20 | if (number >= 2) 21 | { 22 | primes.push_back(2); 23 | } 24 | if (number == 2) 25 | { 26 | primes.push_back(2); 27 | cout << getIndex(primes, 2); 28 | return 0; 29 | } 30 | if (number > 2) 31 | { 32 | for (int i = 3; i <= number; i++) 33 | { 34 | if (i % 2 != 0 && i % 4 != 0) 35 | { 36 | primes.push_back(i); 37 | } 38 | } 39 | } 40 | cout << getIndex(primes, number); 41 | } -------------------------------------------------------------------------------- /sumPrimeNumbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int getSum(int limit) 5 | { 6 | int len = limit; 7 | int i = 2; 8 | int ex = 2; 9 | int sum = 2; 10 | while (i < len) 11 | { 12 | if (i != ex && i % ex != 0) 13 | { 14 | sum += i; 15 | } 16 | i++; 17 | } 18 | 19 | return sum; 20 | } 21 | int getProduct(int limit) 22 | { 23 | int len = limit; 24 | int i = 2; 25 | int ex = 2; 26 | int sum = 2; 27 | while (i < len) 28 | { 29 | if (i != ex && i % ex != 0) 30 | { 31 | sum = sum * i; 32 | } 33 | i++; 34 | } 35 | 36 | return sum; 37 | } 38 | int main() 39 | { 40 | cout << " sum of prime numbers between 1 and 100 : " << getSum(100) << endl; 41 | cout << " product of prime numbers between 1 and 100 : " << getProduct(100) << endl; 42 | return 0; 43 | } -------------------------------------------------------------------------------- /subsets.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | void getSUbs(vector &A, vector> &res, vector &subsets, int index) 6 | { 7 | 8 | res.push_back(subsets); 9 | for (int i = index; i < A.size(); i++) 10 | { 11 | subsets.push_back(A[i]); 12 | cout << " hello " << endl; 13 | getSUbs(A, res, subsets, i + 1); 14 | subsets.pop_back(); 15 | } 16 | return; 17 | } 18 | 19 | vector> subsets(vector &A) 20 | { 21 | vector subsets; 22 | vector> res; 23 | int index = 0; 24 | getSUbs(A, res, subsets, index); 25 | return res; 26 | } 27 | 28 | int main() 29 | { 30 | vector array = {1, 2, 3}; 31 | vector> res = subsets(array); 32 | for (int i = 0; i < res.size(); i++) 33 | { 34 | for (int j = 0; j < res[i].size(); j++) 35 | cout << res[i][j] << " "; 36 | cout << endl; 37 | } 38 | 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /ntth-prime-number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool isPrime(int number) 5 | { 6 | bool res; 7 | if (number == 0 || number == 1) 8 | { 9 | res = false; 10 | } 11 | 12 | for (int i = 2; i < number; i++) 13 | { 14 | if (number % i == 0) 15 | { 16 | res = false; 17 | break; 18 | } 19 | else 20 | { 21 | res = true; 22 | break; 23 | } 24 | } 25 | return res; 26 | } 27 | int getNthPrime(int number) 28 | { 29 | int i; 30 | int index = 0; 31 | 32 | for (i = number; i >= 2; i--) 33 | { 34 | if (isPrime(i)) 35 | { 36 | return i; 37 | break; 38 | }else{ 39 | cout << " npot prime num " <> n; 49 | cout << " index :" << getNthPrime(1) << endl; 50 | 51 | return 0; 52 | } -------------------------------------------------------------------------------- /oddvalent_arrays.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | int isOdd_valent(int arr[], int len){ 7 | vector result{}; 8 | int j = 0; 9 | int count = 0; 10 | while(j < len){ 11 | for(int i = j; i < len; i++){ 12 | if(arr[i] == arr[j]){ 13 | result.push_back(1); 14 | } 15 | } 16 | if(arr[j] % 2 != 0){ 17 | result.push_back(2); 18 | } 19 | j++; 20 | } 21 | 22 | if(std::count(result.begin(), result.end(), 2)){ 23 | int i = 0; 24 | while(i < result.size()){ 25 | if(result[i] == 2){ 26 | count++; 27 | } 28 | i++; 29 | } 30 | 31 | if(count > 1){ 32 | return 1; 33 | }else{ 34 | return 0; 35 | } 36 | 37 | }else{ 38 | return 0; 39 | } 40 | } 41 | int main(){ 42 | 43 | 44 | int numbers[5] = {2, 2, 2, 4, 4}; 45 | cout << isOdd_valent(numbers, 5); 46 | 47 | return 0; 48 | } -------------------------------------------------------------------------------- /duplicate-numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void duplicated(int arr[]) 4 | { 5 | int maxfreq = 0; 6 | int i = 0; 7 | int initialCount; 8 | 9 | for (i = 0; i < 4; i++) 10 | { 11 | initialCount = 1; 12 | for (int j = i + 1; j < 4; j++) 13 | { 14 | if (arr[i] == arr[j]) 15 | { 16 | initialCount++; 17 | } 18 | if (initialCount > maxfreq) 19 | { 20 | maxfreq = initialCount; 21 | } 22 | } 23 | } 24 | 25 | while (i < 4) 26 | { 27 | for (int j = i + 1; j < 4; j++) 28 | { 29 | if (arr[i] == arr[j]) 30 | { 31 | initialCount++; 32 | } 33 | } 34 | 35 | i++; 36 | } 37 | if (initialCount == maxfreq) 38 | { 39 | cout << arr[i] << " "; 40 | } 41 | 42 | } 43 | int main() 44 | { 45 | 46 | int numbers[4] = {4, 5, 5, 7}; 47 | duplicated(numbers); 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /prime_product.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef vector vi; 4 | 5 | 6 | int equal(vi arr, int n){ 7 | int i =0; 8 | int result = 0; 9 | while(i < arr.size()){ 10 | for(int j = i; j < arr.size(); j++){ 11 | if(arr[i] * arr[j] == n){ 12 | result = 1; 13 | break; 14 | }else{ 15 | continue; 16 | } 17 | } 18 | i++; 19 | } 20 | return result; 21 | } 22 | int isPrimeProduct(int n) 23 | { 24 | vector factors = {2}; 25 | int i = 2; 26 | int res = 0; 27 | int number = 2; 28 | while (i < n) 29 | { 30 | if (i != number && i % 2 != 0) 31 | { 32 | factors.push_back(i); 33 | if(equal(factors,n)){ 34 | res = 1; 35 | break; 36 | } 37 | } 38 | i++; 39 | } 40 | 41 | return res; 42 | } 43 | int main() 44 | { 45 | int number = 55; 46 | cout << isPrimeProduct(number) << endl; 47 | 48 | return 0; 49 | } -------------------------------------------------------------------------------- /insert.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void insert(int index, int value, int arr[]) 5 | { 6 | int len = sizeof(arr) / sizeof(arr[0]); 7 | int j = len; 8 | while (j > index) 9 | { 10 | arr[j] = arr[j - 1]; 11 | j--; 12 | } 13 | arr[index] = value; 14 | 15 | for (int i = 0; i <= len; i++) 16 | { 17 | cout << arr[i] << endl; 18 | } 19 | 20 | } 21 | 22 | void deleteArr(int index, int arr[]){ 23 | int i = 0; 24 | cout << "size" <= index){ 27 | arr[i] = arr[i+1]; 28 | } 29 | i++; 30 | } 31 | for (int j = 0; j < sizeof(arr) / 2; j++) 32 | { 33 | cout <<"Element on index " << j+1 << " : " << arr[j] << endl; 34 | } 35 | 36 | 37 | } 38 | int main() 39 | { 40 | int numbers[] = {45, 56, 30,48}; 41 | int main[] = {45,3,5,56}; 42 | insert(2, 4, main); 43 | cout << "========================" < 2 | using namespace std; 3 | bool search(int arr[6], int key, int len) 4 | { 5 | int res = false; 6 | int low = 0; 7 | int high = len; 8 | while (low < high) 9 | { 10 | int mid = (high + low) / 2; 11 | if (arr[mid] == key) 12 | { 13 | res = true; 14 | break; 15 | } 16 | else 17 | { 18 | if (arr[mid] > key) 19 | { 20 | high = mid - 1; 21 | } 22 | else 23 | { 24 | low = mid + 1; 25 | } 26 | } 27 | } 28 | return res; 29 | } 30 | 31 | int isBean(int arr[], int len) 32 | { 33 | if (search(arr, 9, len) && search(arr, 13, len)) 34 | { 35 | return 1; 36 | } 37 | else 38 | { 39 | 40 | return 0; 41 | } 42 | 43 | cout << " hello world " << endl; 44 | } 45 | int main() 46 | { 47 | 48 | int numbers[6]{1, 2, 3, 9, 6, 13}; 49 | int numbers2[3]{9, 6, 18}; 50 | cout << isBean(numbers2, 3) << endl; 51 | return 0; 52 | } -------------------------------------------------------------------------------- /centeredArray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool solve(vector arr){ 5 | int found = 0; 6 | int i; 7 | int length = sizeof(arr)/sizeof(arr[0]); 8 | int middle = length / 2; 9 | for(i = 0 ; i < length; i++){ 10 | if(arr[i] == arr[middle]){ 11 | continue; 12 | } 13 | if(arr[i] >= arr[middle]){ 14 | found += 1; 15 | }else{ 16 | continue;; 17 | } 18 | } 19 | if(found == length - 1){ 20 | return true; 21 | }else{ 22 | return false; 23 | } 24 | } 25 | 26 | int findDiffrence(vector arr){ 27 | int length = arr.size(); 28 | int oddSum = 0; 29 | int EvenSum = 0; 30 | for( int i = 0; i < length; i++){ 31 | if(arr[i] % 2 == 0){ 32 | EvenSum += arr[i]; 33 | }else{ 34 | oddSum += arr[i]; 35 | } 36 | } 37 | return oddSum - EvenSum; 38 | } 39 | int main(){ 40 | vector numbers = {1,2}; 41 | // bool result = solve(numbers); 42 | int dif = findDiffrence(numbers); 43 | cout << "result : " << dif < 2 | using namespace std; 3 | typedef vector> vi; 4 | typedef vector v; 5 | 6 | void printArr(vi arr) 7 | { 8 | 9 | cout << " hello " < 16 | using namespace std; 17 | 18 | int isMagic(int arr[], int len) 19 | { 20 | 21 | int i = 0; 22 | int max = 0; 23 | while (i < len) 24 | { 25 | if (arr[i] % 2 != 0) 26 | { 27 | max += arr[i]; 28 | } 29 | 30 | i++; 31 | } 32 | 33 | if (max == arr[0]) 34 | { 35 | return 1; 36 | } 37 | else 38 | { 39 | return 0; 40 | } 41 | } 42 | int main() 43 | { 44 | int numbers[5] = {8, 3, 4, 5, 6}; 45 | cout << isMagic(numbers, 5); 46 | 47 | return 0; 48 | } -------------------------------------------------------------------------------- /q2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int val; 6 | string result; 7 | string grade; 8 | int a = 12; int b = 25; 9 | 10 | // cout<< "Enter marks : "; 11 | // cin>>val; 12 | // result = val >= 20 ? "passed " : "failed"; 13 | // grade = val >= 16 ? "A" : val > 14 ? " D " : val > 10 ? " C" : "F"; 14 | 15 | //bitwise and operator oprator will compare bits instead of comparing expressions like logical and operator 16 | // cout << " (a & b ) equals to: " << ( a & b) <> 1) equals to :" << ( a >> 1) << endl; 27 | // cout << " ( a >> 2) equals to :" << ( a >> 2) << endl; 28 | // cout << " ( a >> 3) equals to :" << ( a >> 3) << endl; 29 | 30 | 31 | cout << '10' - '0'; 32 | 33 | // cout << result < 2 | using namespace std; 3 | typedef vector vi; 4 | 5 | int minDistance(int number) 6 | { 7 | int factors[50] = {}; 8 | int count = 0; 9 | for (int i = 1; i <= number; i++) 10 | { 11 | if ((number % i) == 0) 12 | { 13 | factors[count] = i; 14 | count++; 15 | } 16 | } 17 | int mdistance = factors[count - 1] - factors[0]; 18 | for (int j = 0; j < count - 1; j++) 19 | { 20 | int d = 0; 21 | for (int p = j + 1; p < count; p++) 22 | { 23 | d = factors[p] - factors[j]; 24 | if (d < mdistance) 25 | { 26 | mdistance = d; 27 | } 28 | } 29 | } 30 | } 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | int min(int arr, int len){ 42 | 43 | for(int i = 1; i < len ; i++){ 44 | int position = i; 45 | int currentValue = arr[i]; 46 | 47 | while(position >= 0 && arr[position -1] > currentValue){ 48 | arr[position] = arr[position - 1]; 49 | position--; 50 | } 51 | arr[position] = currentValue; 52 | } 53 | return arr[1] - arr[0]; 54 | } 55 | 56 | int main() 57 | { 58 | int number = 8; 59 | int vector factors; 60 | for(int i = 1; i <= number ; i++){ 61 | if(number % i == 0){ 62 | factors.push_back(i); 63 | } 64 | } 65 | cout << min(factors, factors.size()); 66 | 67 | return 0; 68 | } -------------------------------------------------------------------------------- /calculator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef vector vi; 4 | namespace arthmetic 5 | { 6 | 7 | int multiply(int a, int b) 8 | { 9 | return a * b; 10 | } 11 | int divide(int a, int b) 12 | { 13 | if (a != 0) 14 | { 15 | return a / b; 16 | } 17 | else 18 | { 19 | cout << " we can not devide by zero"; 20 | } 21 | } 22 | int add(int a, int b) 23 | { 24 | return a + b; 25 | } 26 | 27 | int substract(int a, int b) 28 | { 29 | return a - b; 30 | } 31 | void print() 32 | { 33 | cout << "Enter first and second number a,b" << endl; 34 | } 35 | 36 | } 37 | 38 | int main() 39 | { 40 | 41 | vi op{"Addition", "substruction", "division", "multiplication"}; 42 | int choice, n1, n2; 43 | char comma; 44 | 45 | for (int i = 0; i < op.size(); i++) 46 | { 47 | cout << i << "." << op[i] << endl; 48 | } 49 | cin >> choice; 50 | switch (choice) 51 | { 52 | case 0: 53 | arthmetic::print(); 54 | cin >> n1 >> comma >> n2; 55 | cout << "asnwer : " << arthmetic::add(n1, n2); 56 | break; 57 | case 1: 58 | arthmetic::print(); 59 | cin >> n1 >> comma >> n2; 60 | cout << "asnwer : " << arthmetic::substract(n1, n2); 61 | break; 62 | case 2: 63 | arthmetic::print(); 64 | cin >> n1 >> comma >> n2; 65 | cout << "asnwer : " << arthmetic::divide(n1, n2); 66 | break; 67 | case 3: 68 | arthmetic::print(); 69 | cin >> n1 >> comma >> n2; 70 | cout << "asnwer : " << arthmetic::multiply(n1, n2); 71 | break; 72 | default: 73 | break; 74 | } 75 | 76 | 77 | return 0; 78 | } -------------------------------------------------------------------------------- /complete_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int sort(int arr[], int len) 5 | { 6 | int i = 1; 7 | while (i < len) 8 | { 9 | 10 | int position = i; 11 | int curent_val = arr[i]; 12 | while (position > 0 && arr[position - 1] > curent_val) 13 | { 14 | arr[position] = arr[position - 1]; 15 | // ==> direction 16 | position--; 17 | } 18 | arr[position] = curent_val; 19 | i++; 20 | } 21 | } 22 | int getMin(int arr[], int len) 23 | { 24 | int i = 0; 25 | int max = 0; 26 | int min = arr[5]; 27 | while (i < len) 28 | { 29 | if ((arr[i] % 2 == 0) && (arr[i] < min)) 30 | { 31 | min = arr[i]; 32 | } 33 | i++; 34 | } 35 | 36 | return min; 37 | } 38 | int getMax(int arr[], int len) 39 | { 40 | int i = 0; 41 | int max = 0; 42 | while (i < len) 43 | { 44 | if (arr[i] > max && arr[i] % 2 == 0) 45 | { 46 | max = arr[i]; 47 | } 48 | i++; 49 | } 50 | 51 | return max; 52 | } 53 | 54 | bool search(int arr[], int len, int key) 55 | { 56 | int low = 0; 57 | int high = len; 58 | bool res = false; 59 | sort(arr, len); 60 | while (low <= high) 61 | { 62 | int mid = (low + high) / 2; 63 | if (arr[mid] == key) 64 | { 65 | res = true; 66 | break; 67 | } 68 | else if (arr[mid] < key) 69 | { 70 | low = mid + 1; 71 | } 72 | else 73 | { 74 | high = mid - 1; 75 | } 76 | } 77 | 78 | return res; 79 | } 80 | int isComplete(int arr[], int len) 81 | { 82 | int min = getMin(arr, len); 83 | int max = getMax(arr, len); 84 | int res = 1; 85 | int i = min + 1; 86 | while (i < max) 87 | { 88 | if (search(arr, 10, i)) 89 | { 90 | cout << i << endl; 91 | continue; 92 | } 93 | else 94 | { 95 | 96 | res = 0; 97 | break; 98 | } 99 | 100 | // cout << " found " << search(arr, 10, i) << " elem " << i << endl; 101 | i++; 102 | } 103 | 104 | return res; 105 | } 106 | int main() 107 | { 108 | int arr[10] = {-5, 6, 2, 3, 2, 4, 5, 11, 8, 7}; 109 | sort(arr, 10); 110 | cout << " finding " << search(arr, 10, 7) << endl; 111 | cout << isComplete(arr, 10) << endl; 112 | return 0; 113 | } -------------------------------------------------------------------------------- /gusingGame.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef vector vi; 4 | typedef vector dt; 5 | 6 | bool seach(string arr, char target) 7 | { 8 | bool result = false; 9 | for (int i = 0; i < arr.size(); i++) 10 | { 11 | if (arr[i] == target) 12 | { 13 | result = true; 14 | break; 15 | } 16 | else 17 | { 18 | continue; 19 | } 20 | } 21 | 22 | return result; 23 | } 24 | 25 | int checkEquality(vi compare, string compareTo) 26 | { 27 | 28 | int result = 0; 29 | for (int i = 0; i < compare.size(); i++) 30 | { 31 | if (compare[i] == compareTo[i]) 32 | { 33 | result += 1; 34 | } 35 | else 36 | { 37 | result += 0; 38 | } 39 | } 40 | 41 | return result; 42 | } 43 | 44 | void printChoices() 45 | { 46 | 47 | dt choices{"Districts", "Plants", "Animals", "Peaples"}; 48 | cout << " Choice the category : " << endl; 49 | for (int i = 0; i < choices.size(); i++) 50 | { 51 | cout << i + 1 << "." << choices[i] << endl; 52 | } 53 | } 54 | 55 | void printResult(vi foundchars, string choice) 56 | { 57 | if (checkEquality(foundchars, choice) == choice.size()) 58 | { 59 | cout << "\nconglatulations, You win!!!!" << endl; 60 | cout << " Name required : " << choice << endl; 61 | cout << "Name given : "; 62 | int i = 0; 63 | while (i < foundchars.size()) 64 | { 65 | cout << foundchars[i]; 66 | i++; 67 | } 68 | } 69 | else 70 | { 71 | cout << "\nSorry you lost! please try again" << endl; 72 | cout << "Name required : " << choice << endl; 73 | cout << "Name given : "; 74 | int i = 0; 75 | while (i < foundchars.size()) 76 | { 77 | cout << foundchars[i]; 78 | i++; 79 | } 80 | } 81 | } 82 | int main() 83 | { 84 | 85 | vector districts{"NYABIHU", "DISTRICTS", "GAKENKE", "MUSANZE"}; 86 | vector plants{"AVOKADO", "MANGOES", "COCOMBLE", "BANANA"}; 87 | vector Animals{"HEN", "CHICKEN", "SHEEP", "COW"}; 88 | vector Peaples{"VALENS", "MURANGWA", "PACIFIQUE", "VAINQUER", "BANJO"}; 89 | string choice = "GAKENKE"; 90 | vi foundchars; 91 | int category; 92 | string main; 93 | char input; 94 | int guesTimes = choice.size(); 95 | int i = 0; 96 | 97 | printChoices(); 98 | 99 | cout << " choose category you want to use in this game : " << endl; 100 | cin >> category; 101 | 102 | cout << " gues the world " << endl; 103 | while (i < guesTimes) 104 | { 105 | switch (category) 106 | { 107 | case 1: 108 | // choice = districts[1 + rand() % districts.size()]; 109 | choice = districts[0 + rand() % districts.size()]; 110 | break; 111 | case 2: 112 | choice = plants[0 + rand() % plants.size()]; 113 | break; 114 | case 3: 115 | choice = Animals[0 + rand() % Animals.size()]; 116 | break; 117 | case 4: 118 | choice = Peaples[0 + rand() % Peaples.size()]; 119 | break; 120 | 121 | default: 122 | cout << "please choose one choice " << endl; 123 | printChoices(); 124 | break; 125 | } 126 | cin >> input; 127 | foundchars.push_back(input); 128 | main[i] = input; 129 | for (int j = 0; j < foundchars.size(); j++) 130 | { 131 | 132 | if (choice[j] == foundchars[j]) 133 | { 134 | cout << choice[j]; 135 | } 136 | else 137 | { 138 | cout << "_"; 139 | } 140 | // if (seach(choice, foundchars[j])) 141 | // { 142 | // cout << foundchars[j]; 143 | // } 144 | // else 145 | // { 146 | // cout << " _"; 147 | // } 148 | } 149 | i++; 150 | } 151 | 152 | printResult(foundchars, choice); 153 | } -------------------------------------------------------------------------------- /guesing-gmae.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | /* author valens NIYONSENGA 5 | Year 2 A 6 | Rwanda coding academy 7 | */ 8 | 9 | const char *animals[7] = {"leopard", "lion", "cat", "monkey", "sheep", "gaot", "chicken"}; 10 | const char *vehicles[7] = {"VAN", "TAX", "BUS", "BICYCLE", "RITCO", "VIRUNGA", "AGATARO"}; 11 | const char *food[7] = {"BANANA", "MANGO", "PINEAPLE", "CASSSAVA", "RICE", "BEANS", "POCHO"}; 12 | const char *students[7] = {"KABANDA", "ALINE", "MURANGWA", "PAZZO", "VALENS", "DIVIN", "KEBIN"}; 13 | 14 | void print() 15 | { 16 | int i = 0; 17 | 18 | char *choices[4] = {"Animals", "Vehicles", "food", "Students"}; 19 | 20 | cout << " choose category for your gaming " << endl; 21 | cout << "" << endl; 22 | while (i < 4) 23 | { 24 | cout << i + 1 << "." << choices[i] << endl; 25 | i++; 26 | } 27 | } 28 | bool check(string name, char target) 29 | { 30 | int i; 31 | bool result = false; 32 | for (i = 0; i < name.size(); i++) 33 | { 34 | if (name[i] == target) 35 | { 36 | result = true; 37 | break; 38 | } 39 | else 40 | { 41 | continue; 42 | } 43 | } 44 | return result; 45 | } 46 | void getResult(string word, string foundString) 47 | { 48 | int count = 0; 49 | for (int i = 0; i < word.size(); i++) 50 | { 51 | if (word[i] == foundString[i]) 52 | { 53 | count += 1; 54 | } 55 | } 56 | 57 | if (count == word.size()) 58 | { 59 | cout << "" << endl; 60 | cout << "\n============== result ===============" << endl; 61 | cout << "" << endl; 62 | cout << "\nExcepected name : " << word << endl; 63 | cout << "" << endl; 64 | cout << "Given name : " << foundString << endl; 65 | cout << "" << endl; 66 | cout << " congratulations ! you win " << endl; 67 | } 68 | else 69 | { 70 | cout << "" << endl; 71 | cout << "\n============== result ===============" << endl; 72 | cout << "" << endl; 73 | cout << "\nExcepected name : " << word << endl; 74 | cout << "" << endl; 75 | cout << "Given name : " << foundString << endl; 76 | cout << "" << endl; 77 | cout << " Sorry ! you lost try again " << endl; 78 | } 79 | } 80 | 81 | void checkExistence(string name, string foundchars) 82 | { 83 | char choice; 84 | int i = 0; 85 | int chances = name.size() - 1; 86 | while (i < name.size()) 87 | { 88 | cin >> choice; 89 | foundchars += choice; 90 | if (chances > 0) 91 | { 92 | cout << "\nyou remain with " << chances << " chances " << endl; 93 | } 94 | for (int j = 0; j < foundchars.size(); j++) 95 | { 96 | 97 | if (name[j] == foundchars[j]) 98 | { 99 | cout << "_"; 100 | } 101 | else 102 | { 103 | cout << name[j]; 104 | } 105 | } 106 | chances--; 107 | i++; 108 | } 109 | 110 | getResult(name, foundchars); 111 | } 112 | int main() 113 | { 114 | 115 | cout << "" << endl; 116 | cout << " how to play a game ? : you are allowed to gues n times depending on your choice category and random word we chose for you " << endl; 117 | cout << "" << endl; 118 | char continueGame; 119 | srand(time(NULL)); 120 | int randomNumber = rand() % (7 - 0) + 0; 121 | int i = 0; 122 | int category; 123 | string name; 124 | string foundchars; 125 | char choice; 126 | 127 | int random; 128 | 129 | do 130 | { 131 | print(); 132 | cin >> category; 133 | cout << " you can start guessing , "; 134 | switch (category) 135 | { 136 | case 1: 137 | name = animals[randomNumber]; 138 | cout << " you have " << name.size() << " chances to gues !" << endl; 139 | break; 140 | case 2: 141 | name = vehicles[random]; 142 | cout << " you have " << name.size() << " chances to gues !" << endl; 143 | break; 144 | case 3: 145 | name = food[randomNumber]; 146 | cout << " you have " << name.size() << " chances to gues !" << endl; 147 | break; 148 | case 4: 149 | name = students[randomNumber]; 150 | cout << " you have " << name.size() << " chances to gues " << endl; 151 | break; 152 | default: 153 | break; 154 | } 155 | checkExistence(name, foundchars); 156 | cout << "" << endl; 157 | cout << " Do you want to continue ? Y for yes and N for no" << endl; 158 | cin >> continueGame; 159 | 160 | } while (continueGame == 'Y' || continueGame == 'y'); 161 | 162 | return 0; 163 | } --------------------------------------------------------------------------------