diff --git a/C++/Question-1.cpp b/C++/Question-1.cpp index 3373a60..7dd4a4c 100644 --- a/C++/Question-1.cpp +++ b/C++/Question-1.cpp @@ -3,11 +3,11 @@ 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]) { - int temp = arr[j]; - arr[j] = arr[j + 1]; - arr[j + 1] = temp; + for (int j = i+1; j < n; j++) { + if (arr[i]>arr[j]) { + int temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; } } } @@ -16,8 +16,8 @@ void bubbleSort(int arr[], int n) { int main() { int arr[] = { 64, 34, 25, 12, 22, 11, 90 }; int n = sizeof(arr) / sizeof(arr[0]); - bubbleSort(arr, n); std::cout << "Sorted array: "; + bubbleSort(arr, n); for (int i = 0; i < n; i++) { std::cout << arr[i] << " "; } diff --git a/C++/Question-1.exe b/C++/Question-1.exe new file mode 100644 index 0000000..da3f1eb 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..4601a91 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.185; } int main() { @@ -20,15 +20,15 @@ int main() { std::cout << "Enter currency (USD/EUR): "; std::cin >> currency; - if (currency == "USD") { - double convertedAmount = usdToEur(amount); - std::cout << "Amount in EUR: " << convertedAmount << std::endl; - } else if (currency == "EUR") { - double convertedAmount = usdToEur(amount); - std::cout << "Amount in USD: " << convertedAmount << std::endl; - } else { - std::cout << "Invalid currency." << std::endl; - } - + +if (currency == "USD") { + double convertedAmount = usdToEur(amount); + std::cout << "Amount in EUR: " << convertedAmount << std::endl; +} else if (currency == "EUR") { + double convertedAmount = eurToUsd(amount); // Corrected function call + std::cout << "Amount in USD: " << convertedAmount << std::endl; +} else { + std::cout << "Invalid currency." << std::endl; +} return 0; } diff --git a/C++/Question-2.exe b/C++/Question-2.exe new file mode 100644 index 0000000..53935eb 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..021dc7c 100644 --- a/C++/Question-3.cpp +++ b/C++/Question-3.cpp @@ -11,9 +11,9 @@ void guessNumber() { std::cout << "Guess the number (between 1 and 100): "; std::cin >> guess; - if (guess > number) { + if (guess <= number) { std::cout << "Too low! Try again." << std::endl; - } else if (guess <= number) { + } else if (guess < number) { std::cout << "Too high! Try again." << std::endl; } else { std::cout << "Congratulations! You guessed the number." << std::endl; diff --git a/C++/Question-3.exe b/C++/Question-3.exe new file mode 100644 index 0000000..1936b8a 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..9f3d027 100644 --- a/C++/Question-4.cpp +++ b/C++/Question-4.cpp @@ -1,24 +1,42 @@ // Password should have atleast 8 characters // Password must have atleast one lowercase character, one uppercase character and a special character -#include -#include - -bool checkPassword(std::string password) { - return password.length() >= 8; -} - -int main() { - std::string password; - std::cout << "Enter a password: "; - std::getline(std::cin, password); - - if (checkPassword(password)) { - std::cout << "Password is valid." << std::endl; - } else { - std::cout << "Password is too short." << std::endl; - } +#include +using namespace std; +int main() +{ + int low_case=0, up_case=0, digit=0, special=0; + string pass; + cout<<"Enter Password"<>pass; + int l=pass.length(),i; + + for(i=0;i=8) + cout<<"strong password."< - +using namespace std; // Function to calculate the factorial of a number int factorial(int n) { + if(n<0){ + return -1; + } + if(n==0||n==1) + return 1; + return n * factorial(n - 1); } int main() { int number; - std::cout << "Enter a number: "; - std::cin >> number; - + cout << "Enter a number: "; + cin >> number; int result = factorial(number); - std::cout << "The factorial of " << number << " is " << result << std::endl; + cout << "The factorial of " << number << " is " << result << endl; return 0; } \ No newline at end of file diff --git a/C++/Question-5.exe b/C++/Question-5.exe new file mode 100644 index 0000000..a4b3877 Binary files /dev/null and b/C++/Question-5.exe differ diff --git a/C++/tempCodeRunnerFile.cpp b/C++/tempCodeRunnerFile.cpp new file mode 100644 index 0000000..9cf5b08 --- /dev/null +++ b/C++/tempCodeRunnerFile.cpp @@ -0,0 +1,2 @@ +// Password should have atleast 8 characters +// Password must have atleast one lowercase character, one uppercase character and a special character \ No newline at end of file