can someone help, fill in the blanks to print all elements of the array using a for loop? int [] arr= new int [7]; ? (int k=0; k < ? ; k++){ console.writeline ( ??? [ k] ); | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

can someone help, fill in the blanks to print all elements of the array using a for loop? int [] arr= new int [7]; ? (int k=0; k < ? ; k++){ console.writeline ( ??? [ k] );

2nd Jul 2016, 8:40 PM
Joyx Kish
Joyx Kish - avatar
7 Answers
0
int * arr=new int[7]; for (int k=0;k<7;k++){ console.writeline(arr[k]); }
2nd Jul 2016, 9:20 PM
Jesús Moncada
Jesús Moncada - avatar
0
your code is c#, not c++. But you could use Console::WriteLine if you are using .NET framework.
2nd Jul 2016, 11:05 PM
Garme Kain
Garme Kain - avatar
0
That's true Grame, thank you for this answer. In c++ i would write : cout<<arr[k]<<endl;
2nd Jul 2016, 11:15 PM
Jesús Moncada
Jesús Moncada - avatar
- 2
Jesus: Yours no. The asker's one. Your code is good for C++ appart from the console.writeline line. Well, i know you could make a custom class Console, create an attribute writeline and instate the class with name console. Then you could use console.writeline.
2nd Jul 2016, 11:12 PM
Garme Kain
Garme Kain - avatar
- 2
Jesus: Even if you wrote cout << arr[k] << endl your program wont work, because you only said that arr has space for 7 integers, you never initialized the array with values and that leds to undefined behaviour.
2nd Jul 2016, 11:19 PM
Garme Kain
Garme Kain - avatar
- 2
Hhhhh
20th Feb 2021, 5:36 AM
ken jhon bela-ong
ken jhon bela-ong - avatar
- 3
my code?
2nd Jul 2016, 11:07 PM
Jesús Moncada
Jesús Moncada - avatar