+ 1

Entering an array of 10 elements replacing the final element of the array with the 2nd element using the pointer

Help me I just started learning C++ please

3rd Nov 2020, 6:36 AM
Plutos
Plutos - avatar
12 Respuestas
0
Алиаскар Куватов ok, #include <stdio.h> int main() { int a[10] = {1,2,3,4,5,6,7,8,9,0}; int* p = a; int t = *(p+9); *(p+9) = *(p+1); *(p+1) = t; printf("%d\n%d", a[9], a[1]); return 0; } // you can use any loop to get input, but idea that i used can be applied here https://code.sololearn.com/c08l2TC7g7zb/?ref=app
3rd Nov 2020, 12:05 PM
Flash
+ 1
Ok Thank you
3rd Nov 2020, 12:22 PM
Plutos
Plutos - avatar
0
do you mean something like this? #include <stdio.h> int main() { int a[10] = {1,2,3,4,5,6,7,8,9,0}; int* p = a; *(p+9) = *(p+1); printf("%d", a[9]); return 0; } // it’s a C file, didn’t notice the tag was C++. But should be the same. https://code.sololearn.com/c08l2TC7g7zb/?ref=app
3rd Nov 2020, 11:20 AM
Flash
0
no
3rd Nov 2020, 11:43 AM
Plutos
Plutos - avatar
0
Enter the array data, and swap the second and last element of the array.
3rd Nov 2020, 11:45 AM
Plutos
Plutos - avatar
0
Input: 1 2 3 4 5 6 7 8 9 0 Output: 1 0 3 4 5 6 7 8 9 2
3rd Nov 2020, 11:46 AM
Plutos
Plutos - avatar
0
Input: 1 2 3 4 5 6 7 8 9 0 Output: 1 0 3 4 5 6 7 8 9 2
3rd Nov 2020, 12:06 PM
Plutos
Plutos - avatar
0
Алиаскар Куватов did you see my code shows the same thing. learn a bit more before complaining
3rd Nov 2020, 12:09 PM
Flash
0
Sorry
3rd Nov 2020, 12:11 PM
Plutos
Plutos - avatar
0
Can I send my code so that you can fix it
3rd Nov 2020, 12:16 PM
Plutos
Plutos - avatar
0
I can’t fix it for you. I showed almost everything. You can use a while/for to get input. Rest should be the same.
3rd Nov 2020, 12:19 PM
Flash
3rd Nov 2020, 12:24 PM
Flash