+ 1

Please point out the mistake.

I wanted the user to enter 5 numbers and store them in an array by using a loop and then display the contents of that array but the output is being shown as - 1 without any input. Please help me with an explanation. https://code.sololearn.com/c2Gp9Q7XG9jp/?ref=app

14th Aug 2018, 10:39 AM
Tanmoy
5 Réponses
+ 6
Because you are writing c program in c++. Also there were some mistakes which I have fixed now. Hope this helps ☺️☺️. https://code.sololearn.com/c4O7O4qDI3Q3/?ref=app
14th Aug 2018, 11:13 AM
Meet Mehta
Meet Mehta - avatar
+ 5
Note putting the \n in scanf requires the next number to follow after a new line so your first line to the input prompt should be blank. The second and beyond should contain a number.
14th Aug 2018, 11:21 AM
John Wells
John Wells - avatar
+ 2
the code need's to look like this: #include <stdio.h> int main() { int arr[10]; for(int x=0;x<5;x++) { scanf("%d",&arr[x]); } for(int y=0;y<5;y++) { printf("%d ",arr[y]); } } And select C programming language, not C++
14th Aug 2018, 11:15 AM
MarJan
MarJan - avatar
+ 2
this is for c++: #include <iostream> int main() { int arr[10]; for(int x=0;x<5;x++) { cin>>arr[x]; } for(int y=0;y<5;y++) { printf("%d ",arr[y]); } return 0; }
14th Aug 2018, 11:24 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 2
Thank you everyone.
14th Aug 2018, 11:41 AM
Tanmoy