A twin primes is a pair of prime numbers such that the diffe
A twin primes is a pair of prime numbers such that the difference between them is 2 (for example, 17 and 19). Write a computer program that finds all the twin primes between 10 and 500. The program displays the results in a two-column matrix in which each row is a twin prime. Do not use MATLAB\'s built-in function isprime. A list of 30 exam scores is: 31, 70, 92, 5, 47, 88, 81, 73, 51, 76, 80, 90, 55, 23, 43, 98, 36, 87, 22, 61, 19, 69, 26, 82, 89, 99, 71, 59, 49, 64 Write a computer program that determines how many grades are between 0 and 19, between 20 and 39, between 40 and 59, between 60 and 79, and between 80 and 100. The results are displayed in the following form: Grades between 0 and 19 2 students Grades between 20 and 39 4 students Grades between 40 and 59 6 students and so on.
Solution
14 ans:
%start the script
J=0; k=1;
For n=11:499
For i=2: n-1
If rem (n, i) =0
J=j+1;
End
End
If==n-2
A (k) =n;
K=k+1;
End
J=0;
End
M=length (a);
Fprintf (‘the twin primes are:\ ’)
For p=1: m-1
If (a (p+1-a (p))==2
Fprintf (%i and %i\ ’, a (p), a (p+1))
End
End
The mat lab output
The twin primes are:
11 and 13
17 and 19
29 and 31
41 and 43
59 and 61
71 and 73
101 and 103
107 and 109
137 and 139
149 and 151
179 and 181
191 and 193
197 and 199
227 and 229
239 and 241
269 and 271
281 and 283
311 and 313
347 and 349
419 and 421
431 and 433
461 and 463

