How to use a counter with a loop
263 ビュー (過去 30 日間)
古いコメントを表示
How do you use a counter with a for loop?
I want to learn how to input a bunch of numbers into a loop and use the counter to find how many "count numbers" I get for that input. Whichever input gets the largest "count number" I want to save that input and display it.
0 件のコメント
回答 (3 件)
Youssef Khmou
2013 年 5 月 6 日
編集済み: Youssef Khmou
2013 年 5 月 6 日
hi,
here is fast way :
N=1:1000;
P=isprime(N);
Prime=find(P==1);
2 件のコメント
Youssef Khmou
2013 年 5 月 6 日
編集済み: Youssef Khmou
2013 年 5 月 6 日
hi, according to this description here is the translation :
N=1000;
c=[2 3 5 7 11 13];
counter=0;
ctr=1;
for x=1:N
if sum(rem(x,c))==0
counter=counter+1;
P(ctr)=x;
ctr=ctr+1;
else
continue;
end
end
But logically that s not right . counter is 0 .
Youssef Khmou
2013 年 5 月 6 日
編集済み: Youssef Khmou
2013 年 5 月 6 日
hi,
Second way :
K=primes(1000);
Third way :
N=1000;
c=[2 3 5 7];
counter=1;
for x=1:N
V=mod(x,c);
F=V(V==0);
if isempty(F)
Prime(counter)=x;
counter=counter+1;
else
continue;
end
end
0 件のコメント
Sakhumzi
2024 年 5 月 3 日
N=1000;
c=[2 3 5 7];
counter=1;
for x=1:N
V=mod(x,c);
F=V(V==0);
if isempty(F)
Prime(counter)=x;
counter=counter+1;
else
continue;
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!