-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
252 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
main () : proc | ||
|
||
bsort (n : int, x : reference int []) : proc | ||
|
||
swap (x : reference int, y : reference int) : proc | ||
t : int; | ||
{ | ||
t = x; | ||
x = y; | ||
y = t; | ||
} | ||
|
||
changed : byte; | ||
i : int; | ||
|
||
{ -- bsort | ||
changed = 'y'; | ||
while (changed == 'y') { | ||
changed = 'n'; | ||
i = 0; | ||
while (i < n-1) { | ||
if (x[i] > x[i+1]) { | ||
swap(x[i], x[i+1]); | ||
changed = 'y'; | ||
} | ||
i = i+1; | ||
} | ||
} | ||
} -- bsort | ||
|
||
writeArray (msg : reference byte [], n : int, x : reference int []) : proc | ||
i : int; | ||
{ | ||
writeString(msg); | ||
i = 0; | ||
while (i < n) { | ||
if (i > 0) writeString(", "); | ||
writeInteger(x[i]); | ||
i = i+1; | ||
} | ||
writeString("\n"); | ||
} | ||
|
||
seed : int; | ||
x : int [16]; | ||
i : int; | ||
|
||
{ -- main | ||
seed = 65; | ||
i = 0; | ||
while (i < 16) { | ||
seed = (seed * 137 + 220 + i) % 101; | ||
x[i] = seed; | ||
i = i+1; | ||
} | ||
writeArray("Initial array: ", 16, x); | ||
bsort(16, x); | ||
writeArray("Sorted array: ", 16, x); | ||
} -- main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
cancer(): proc | ||
is_it (n:int, source:reference byte[]):int | ||
i:int; | ||
|
||
{ | ||
n=n-1; | ||
i=0; | ||
while ( i < (n/2 + 1) ) | ||
{ | ||
if(source[i]!=source[n-i]) | ||
return 1; | ||
i=i+1; | ||
} | ||
return 0; | ||
} | ||
|
||
n:int; | ||
source:byte[31]; | ||
|
||
{ | ||
writeString("Give a string with maximum length 30: "); | ||
readString(30, source); | ||
n=0; | ||
while (source[n]!='\0') | ||
n=n+1; | ||
n=n-1;(*��������� �� n *) | ||
if (is_it(n, source)==1) --�������� ���������� ��������� | ||
writeString("\nIs not cancern..."); | ||
else | ||
writeString("\nIs cancern..."); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
main() : proc | ||
n : int; | ||
lcv : int; | ||
flag : int; | ||
|
||
{ | ||
writeString("Enter value of N > "); | ||
n = readInteger(); | ||
lcv = 2; flag = 1; | ||
while (lcv <= (n / 2)) | ||
{ | ||
if ((n % lcv) == 0) { | ||
if (flag != 0) { writeString("The non-trivial factors of "); writeInteger(n); writeString(" are: \n"); } | ||
flag = 0; | ||
writeInteger(lcv); writeChar('\n'); | ||
} | ||
lcv = lcv + 1; | ||
} | ||
if (flag != 0 ) { writeInteger(n); writeString(" is prime\n"); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
gcd():proc | ||
find_gcd(a:int, b:int):int | ||
i:int; | ||
{ | ||
if (a>b) | ||
i=a; | ||
else | ||
i=b; | ||
|
||
while (i>1) | ||
{ | ||
if ((a%i==0) & (b%i==0)) | ||
return i; | ||
i=i-1; | ||
} | ||
return 1; | ||
|
||
} | ||
|
||
a:int; | ||
b:int; | ||
|
||
{ | ||
writeString("Give the first integer: "); | ||
a=readInteger(); | ||
writeString("Give the second integer: "); | ||
b=readInteger(); | ||
writeString("\nThe gcd you are looking for is "); | ||
writeInteger(find_gcd(a, b)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
solve () : proc | ||
|
||
hanoi (rings : int, source : reference byte [], | ||
target : reference byte [], auxiliary : reference byte []) : proc | ||
|
||
move (source : reference byte [], target : reference byte[]) : proc | ||
{ | ||
writeString("Moving from "); | ||
writeString(source); | ||
writeString(" to "); | ||
writeString(target); | ||
writeString(".\n"); | ||
} | ||
|
||
{ -- hanoi | ||
if (rings >= 1) { | ||
hanoi(rings-1, source, auxiliary, target); | ||
move(source, target); | ||
hanoi(rings-1, auxiliary, target, source); | ||
} | ||
} -- hanoi | ||
|
||
NumberOfRings : int; | ||
|
||
{ -- solve | ||
writeString("Rings: "); | ||
NumberOfRings = readInteger(); | ||
hanoi(NumberOfRings, "left", "right", "middle"); | ||
} -- solve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
hello () : proc | ||
{ | ||
writeString("Hello world!\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
main () : proc | ||
|
||
prime (n : int) : int | ||
i : int; | ||
{ | ||
if (n < 0) return prime(-n); | ||
else if (n < 2) return 0; | ||
else if (n == 2) return 1; | ||
else if (n % 2 == 0) return 0; | ||
else { | ||
i = 3; | ||
while (i <= n / 2) { | ||
if (n % i == 0) | ||
return 0; | ||
i = i + 2; | ||
} | ||
return 1; | ||
} | ||
} | ||
|
||
limit : int; | ||
number : int; | ||
counter : int; | ||
|
||
{ -- main | ||
writeString("Limit: "); | ||
limit = readInteger(); | ||
writeString("Primes:\n"); | ||
counter = 0; | ||
if (limit >= 2) { | ||
counter = counter + 1; | ||
writeInteger(2); | ||
writeString("\n"); | ||
} | ||
if (limit >= 3) { | ||
counter = counter + 1; | ||
writeInteger(3); | ||
writeString("\n"); | ||
} | ||
number = 6; | ||
while (number <= limit) { | ||
if (prime(number - 1) == 1) { | ||
counter = counter + 1; | ||
writeInteger(number - 1); | ||
writeString("\n"); | ||
} | ||
if (number != limit & prime(number + 1) == 1) { | ||
counter = counter + 1; | ||
writeInteger(number + 1); | ||
writeString("\n"); | ||
} | ||
number = number + 6; | ||
} | ||
|
||
writeString("\nTotal: "); | ||
writeInteger(counter); | ||
writeString("\n"); | ||
} -- main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
main () : proc | ||
|
||
r : byte [32]; | ||
|
||
reverse (s : reference byte []) : proc | ||
i : int; | ||
l : int; | ||
{ | ||
l = strlen(s); | ||
i = 0; | ||
while (i < l) { | ||
r[i] = s[l-i-1]; | ||
i = i+1; | ||
} | ||
r[i] = '\0'; | ||
} | ||
|
||
{ -- main | ||
reverse("\n!dlrow olleH"); | ||
writeString(r); | ||
} -- main |