Array is defined by the user (size & members)
1 2 3 4 5 6 7 8 9 10
input k
if index (not the number) can be divided with the k, then that number (not the index is printed).
For example
1 2 3 4 5 6 7 8 9 10 array
k=3
Solution is: 4 7 10
Array is defined by the user (size & members)
1 2 3 4 5 6 7 8 9 10
input k
if index (not the number) can be divided with the k, then that number (not the index is printed).
For example
1 2 3 4 5 6 7 8 9 10 array
k=3
Solution is: 4 7 10
Where is YOUR code?
Code:#include <stdio.h> #define MAX 100 int main() { int brojevi[MAX]; int n, i, k, indikator; printf("Array input: "); scanf("%d", &n); if(n<1 || n>MAX) { printf("Error !\n"); return -1; } printf("Insert array elements: "); for(i=0;i<n;i++) scanf("%d", &brojevi[i]); /printf("Insert number k: "); scanf("%d", &k); if(k == 0) { printf("Error!\n"); return -1; } indikator = 0; for(i=0;i<n;i++){ if(brojevi[i]%k == 0) { indikator = 1; printf("%d ",i); } } if(indikator == 0){ printf("there is no index that can be divided with %d!\n",k); } return 0; }
you want the program to return the number if the arrays index is devisable by k ie if k was 2 it would return every other element or do you want the index of the integers in the array that are devisable by k
"you want the program to return the number if the arrays index is devisable by k" yes, this is what i want
have a look at the for loop then
well as i said it depends which of the above you wanted to do you have it set for the second option not the first
ok... i agree...help me to set it up for the first option..thanks.
here is a hint
will cycle through the elements of my array and print out to screen the value in each element of my arrayCode:for(i =0; i <8; i++) { printf("%d", myarray[i]) }
will print out the value of iCode:for (i=0;i<7;i++) { printf{"%d",i); }
coop
the point is you are dividing the elements by k not the index
Can you please do the whole code here, so I can test on my side. Thank you.
If the index can be divided by the k (input by the user at the beginning), then I need to printf that element, not the index...
divides he elementCode:myarray[i] % 2