Index of the first number divisible by 3

17 views (last 30 days)
Emanual  Alemshet
Emanual Alemshet on 7 Apr 2020
Answered: KSSV on 7 Apr 2020
How do I answer this using for loop, any hint or answer?
Write a script that given a vector, called A, of n numbers, outputs the index of the first number divisible by 3.
Sample Output: Given A = [5, 4, 6, 7, 3]
the answer should read as follow:
The index first number divisible by 3 is: 3

Answers (1)

KSSV
KSSV on 7 Apr 2020
idx = find(mod(A,3)==0) ;
iwant = idx(1)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!