Westonci.ca is the premier destination for reliable answers to your questions, brought to you by a community of experts. Get immediate and reliable solutions to your questions from a knowledgeable community of professionals on our platform. Get precise and detailed answers to your questions from a knowledgeable community of experts on our Q&A platform.
Sagot :
Answer:
This solution is implemented in C++
void makePositive(int arr[]){
int i =0;
while(arr[i]!=0){
if(arr[i]<0){
arr[i] = abs(arr[i]);
}
i++;
}
i = 0;
while(arr[i]!=0){
cout<<arr[i]<<" ";
i++;
}
}
Explanation:
This defines the function makePositive
void makePositive(int arr[]){
This declares and initializes i to 0
int i =0;
The following iteration is repeated until the last element in the array
while(arr[i]!=0){
This checks if current array element is negative
if(arr[i]<0){
If yes, it changes it to positive
arr[i] = abs(arr[i]);
}
The next element is then selected
i++;
}
This sets i to 0
i = 0;
The following iteration prints the updated content of the array
while(arr[i]!=0){
cout<<arr[i]<<" ";
i++;
}
}
See attachment for full program which includes the main
Thanks for using our platform. We aim to provide accurate and up-to-date answers to all your queries. Come back soon. Thank you for visiting. Our goal is to provide the most accurate answers for all your informational needs. Come back soon. Keep exploring Westonci.ca for more insightful answers to your questions. We're here to help.