Thread: Index Array simpe task. Need help.

  1. #16
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    Code:
     if (myarray[i] %2 == 0)// says if the elemen in my array at index i is devisable by k 
        {
            // do stuff
        }
    as sad divides the element in the array at index i by k you want it the other way round

  2. #17
    Registered User
    Join Date
    May 2019
    Posts
    21
    Quote Originally Posted by cooper1200 View Post
    Code:
    myarray[i] % 2
    divides he element
    Code:
     if(brojevi[i]%k == 0)
    Isn't this the same?

  3. #18
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    yep it is... that's why you aren't getting the output you want because it is dividing the element not the index

  4. #19
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    if you enetered the numbers 1 3 5 9 7 8 and 2 for k you would get the output 5 as in index 5 where you said you want the output 1, 5 and 7 as in the elements at location 0, 2 and 4

  5. #20
    Registered User
    Join Date
    May 2019
    Posts
    21
    Quote Originally Posted by cooper1200 View Post
    if you enetered the numbers 1 3 5 9 7 8 and 2 for k you would get the output 5 as in index 5 where you said you want the output 1, 5 and 7 as in the elements at location 0, 2 and 4
    So, how to fix this?

  6. #21
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    ask yourself what is the variable i being used for is it to index the array
    what does printf("%d", myarray[i]) give is it the value stored at index i or is it the index if its the value how do i divide the index by k

  7. #22
    Registered User
    Join Date
    May 2019
    Posts
    21
    Quote Originally Posted by cooper1200 View Post
    ask yourself what is the variable i being used for is it to index the array
    what does printf("%d", myarray[i]) give is it the value stored at index i or is it the index if its the value how do i divide the index by k
    Feel free to shoot me, or show me complete code

  8. #23
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    i is being used as an index
    so divide i by k not the element

  9. #24
    Registered User
    Join Date
    May 2019
    Posts
    21
    if(i%k == 0)

    This doesn't give good result

  10. #25
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    whats wrong with it

  11. #26
    Registered User
    Join Date
    May 2019
    Posts
    21
    This...Index Array simpe task. Need help.-untitled-jpg

  12. #27
    Registered User
    Join Date
    May 2019
    Posts
    21
    Result should be here 4. Right?

  13. #28
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    so why are you still printing out the index not the element you know how to address the element you did it for your if statement

  14. #29
    Registered User
    Join Date
    May 2019
    Posts
    21
    No, i don't know... help me

  15. #30
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    printf("%d",myarray[i]) like you had in the if statement

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-13-2013, 12:01 AM
  2. Replies: 8
    Last Post: 04-04-2012, 09:03 PM
  3. Replies: 2
    Last Post: 12-31-2007, 11:40 AM
  4. Simpe question about graphic
    By kennny2004 in forum C++ Programming
    Replies: 3
    Last Post: 04-27-2006, 02:28 PM
  5. Simpe graphics in C
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-07-2001, 08:27 PM

Tags for this Thread