Index of the first number divisible by 3

18 ビュー (過去 30 日間)
Emanual  Alemshet
Emanual Alemshet 2020 年 4 月 7 日
回答済み: KSSV 2020 年 4 月 7 日
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

回答 (1 件)

KSSV
KSSV 2020 年 4 月 7 日
idx = find(mod(A,3)==0) ;
iwant = idx(1)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by