Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

Write a program that uses a dynamic array that contains 5 items of dou (1).docx

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité

Consultez-les par la suite

1 sur 1 Publicité

Write a program that uses a dynamic array that contains 5 items of dou (1).docx

Télécharger pour lire hors ligne

Write a program that uses a dynamic array that contains 5 items of double values. The size of the array is entered when the program is run. Also the 5 values must be entered. These tasks are done in the main() function. Then write a function to display the 5 values. The function must have a pointer variable as a parameter. The function is called from the main().
Solution
#include <iostream>
void printInt(int printable){
std::cout << \"The int you passed in has value \" << printable << std::endl;
}
int main(){
int my_array[5];

// Reminder: always initialize your array values!
for(int i = 0; i < 5; i++)
my_array[i] = i * 2;

for(int i = 0; i < 5; i++)
printInt(my_array[i]); // <-- We pass in a dereferenced array element
}
.

Write a program that uses a dynamic array that contains 5 items of double values. The size of the array is entered when the program is run. Also the 5 values must be entered. These tasks are done in the main() function. Then write a function to display the 5 values. The function must have a pointer variable as a parameter. The function is called from the main().
Solution
#include <iostream>
void printInt(int printable){
std::cout << \"The int you passed in has value \" << printable << std::endl;
}
int main(){
int my_array[5];

// Reminder: always initialize your array values!
for(int i = 0; i < 5; i++)
my_array[i] = i * 2;

for(int i = 0; i < 5; i++)
printInt(my_array[i]); // <-- We pass in a dereferenced array element
}
.

Publicité
Publicité

Plus De Contenu Connexe

Plus par drosa1 (20)

Plus récents (20)

Publicité

Write a program that uses a dynamic array that contains 5 items of dou (1).docx

  1. 1. Write a program that uses a dynamic array that contains 5 items of double values. The size of the array is entered when the program is run. Also the 5 values must be entered. These tasks are done in the main() function. Then write a function to display the 5 values. The function must have a pointer variable as a parameter. The function is called from the main(). Solution #include <iostream> void printInt(int printable){ std::cout << "The int you passed in has value " << printable << std::endl; } int main(){ int my_array[5]; // Reminder: always initialize your array values! for(int i = 0; i < 5; i++) my_array[i] = i * 2; for(int i = 0; i < 5; i++) printInt(my_array[i]); // <-- We pass in a dereferenced array element }

×