Hi,
I want to create a program and insert some numbers into an array
for example:
> test1 //start the program
2 4 6 5 3 20 30 60 50 40 //insert thoes values into array in the program
how can i do it?
Printable View
Hi,
I want to create a program and insert some numbers into an array
for example:
> test1 //start the program
2 4 6 5 3 20 30 60 50 40 //insert thoes values into array in the program
how can i do it?
You've left out so many details I am unable to answer your question.
You want to insert them by keyboarding them into the array?
Remember that all C arrays begin with array[0], and stop at array[size - 1]. So if your arrray has space for 10 items, the last number it can hold will be in array[9], not array[10].Code:int i, size_of_the_array;
for(i = 0; i < size_of_ the_array; i++) {
printf("\n Enter a number %d: ", i+1);
scanf("%d", &array[i]);
}
somthing more like:
int i, size_of_the_array;
printf("\n Enter a number %d: ", i+1);
scanf("%d", &array[i]);
// the input should be a lot of numbers with space between every two //
so i dont think the scanf above will work... maybe to insert all the number into a string and then work on the string... or somthing else... im not sure....
do u know how to do it?
thnx.
Use loops for that purpose, as Adak has already explained.