+ 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
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
+ 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.
+ 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++
+ 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;
}
+ 2
Thank you everyone.