diff --git a/C++/Question-1.cpp b/C++/Question-1.cpp index 3373a60..e6e355e 100644 --- a/C++/Question-1.cpp +++ b/C++/Question-1.cpp @@ -3,8 +3,8 @@ void bubbleSort(int arr[], int n) { for (int i = 0; i < n; i++) { - for (int j = i; j < n - i - 1; j++) { - if (arr[j] < arr[j + 1]) { + for (int j = 0; j < n -i-1; j++) { + if (arr[j] > arr[j + 1]) { int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; diff --git a/C++/Question-1.exe b/C++/Question-1.exe new file mode 100644 index 0000000..480e503 Binary files /dev/null and b/C++/Question-1.exe differ diff --git a/C++/Question-2.cpp b/C++/Question-2.cpp index b2e8ef2..cbd8171 100644 --- a/C++/Question-2.cpp +++ b/C++/Question-2.cpp @@ -4,11 +4,11 @@ #include double usdToEur(double amount) { - return amount * 0.8; + return amount * 0.84375; } double eurToUsd(double amount) { - return amount * 1.2; + return amount * 1.185185185185185; } int main() { @@ -24,7 +24,7 @@ int main() { double convertedAmount = usdToEur(amount); std::cout << "Amount in EUR: " << convertedAmount << std::endl; } else if (currency == "EUR") { - double convertedAmount = usdToEur(amount); + double convertedAmount = eurToUsd(amount); std::cout << "Amount in USD: " << convertedAmount << std::endl; } else { std::cout << "Invalid currency." << std::endl; diff --git a/C++/Question-2.exe b/C++/Question-2.exe new file mode 100644 index 0000000..ce3ba51 Binary files /dev/null and b/C++/Question-2.exe differ diff --git a/C++/Question-3.cpp b/C++/Question-3.cpp index e6116b7..1b44437 100644 --- a/C++/Question-3.cpp +++ b/C++/Question-3.cpp @@ -12,9 +12,9 @@ void guessNumber() { std::cin >> guess; if (guess > number) { - std::cout << "Too low! Try again." << std::endl; - } else if (guess <= number) { std::cout << "Too high! Try again." << std::endl; + } else if (guess <= number) { + std::cout << "Too low! Try again." << std::endl; } else { std::cout << "Congratulations! You guessed the number." << std::endl; break; diff --git a/C++/Question-3.exe b/C++/Question-3.exe new file mode 100644 index 0000000..2eeb204 Binary files /dev/null and b/C++/Question-3.exe differ diff --git a/C++/Question-4.cpp b/C++/Question-4.cpp index 83db22b..ed7be94 100644 --- a/C++/Question-4.cpp +++ b/C++/Question-4.cpp @@ -5,7 +5,20 @@ #include bool checkPassword(std::string password) { - return password.length() >= 8; + bool lc= false; + bool uc= false; + for(int i =0;i='!'){ + lc=true; + break; + } + if(password[i]<='a'&&password[i]>='z'){ + lc=true; + break; + } + } + if(password.length() >= 8 &&lc==true&uc==true) return true; + return false; } int main() { @@ -17,7 +30,7 @@ int main() { if (checkPassword(password)) { std::cout << "Password is valid." << std::endl; } else { - std::cout << "Password is too short." << std::endl; + std::cout << "Password is invalid." << std::endl; } return 0; diff --git a/C++/Question-4.exe b/C++/Question-4.exe new file mode 100644 index 0000000..03d60b4 Binary files /dev/null and b/C++/Question-4.exe differ diff --git a/C++/Question-5.cpp b/C++/Question-5.cpp index 036a83c..a1852f5 100644 --- a/C++/Question-5.cpp +++ b/C++/Question-5.cpp @@ -2,6 +2,7 @@ // Function to calculate the factorial of a number int factorial(int n) { + if(n==0) return 1; return n * factorial(n - 1); } diff --git a/C++/Question-5.exe b/C++/Question-5.exe new file mode 100644 index 0000000..716d6b2 Binary files /dev/null and b/C++/Question-5.exe differ