Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Débogue le code C++ donné
Vous pouvez interroger un modèle directement et tester les résultats renvoyés lors de l'utilisation de différentes valeurs de paramètre en utilisant la console Cloud ou en appelant directement l'API Vertex AI.
Debug the code:
```
#include
#include
using namespace std;
void check_sum_parity(int* arr, int arrayLength) {
int sum_of_numbers = 0;
for (int i = 0; i++; i < arrayLength) {
sum_of_numbers += arr[i];
}
if (sum_of_numbers % 2 == 0) {
cout << "Sum is odd." << endl;
}
else {
cout << "Sum is even." << endl;
}
}
int main(void) {
int arr[] = { 10, 2, 21, 50};
int arrayLength = sizeof(arr) / sizeof(int);
check_sum_parity(arr, arrayLength);
}
```
Réponse
The issue with the code is in the for loop condition. The condition `i++` is
incorrect. It should be `i < arrayLength`. The correct code is:
```
#include
#include
using namespace std;
void check_sum_parity(int* arr, int arrayLength) {
int sum_of_numbers = 0;
for (int i = 0; i < arrayLength; i++) {
sum_of_numbers += arr[i];
}
if (sum_of_numbers % 2 == 0) {
cout << "Sum is even." << endl;
}
else {
cout << "Sum is odd." << endl;
}
}
int main(void) {
int arr[] = { 10, 2, 21, 50};
int arrayLength = sizeof(arr) / sizeof(int);
check_sum_parity(arr, arrayLength);
}
```
Modèle :
gemini-1.0-pro-001
Température :
0.2
Nombre maximal de jetons de sortie :
2 048
TopK :
40
TopP :
0,95
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2024/04/12 (UTC).
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"Problème de traduction"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Autre"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Facile à comprendre"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"J'ai pu résoudre mon problème"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Autre"
}]