Uploaded by Адилет Камза

lab2

advertisement
1)
void sum(int a, int b){
for(int i = a; i<b; i++){
if(i%2==0){
print(i);
}
}
}
void main(){
int a = 1;
int b = 20;
sum(a,b);
}
2)
num sum(a){
num result = 0;
while(a>0){
result = result + (a%10);
a = (a/10).toInt();
}
return result;
}
void main(){
int a = 854;
print(sum(a));
}
3)
num count(a){
num count = 0;
while(a>0){
a = (a/10).toInt();
count = count+1;
}
return count;
}
void main(){
int a = 854;
print(count(a));
}
4)
int max(a){
int i, max = 0;
while(a>0){
i = a%10;
if(i > max){
max = i;
}
a = (a/10).toInt();
}
return max;
}
void main(){
int a = 584;
print(max(a));
}
5)
int fib(a){
int fib1 = 1;
int fib2 = 1;
int fib_sum;
int i = 0;
while (i < a - 2) {
fib_sum = fib1 + fib2;
fib1 = fib2;
fib2 = fib_sum;
i = i + 1;
}
return fib2;
}
void main(){
int a = 10;
print(fib(a));
}
6)
void sum(){
Function operation = (a, b) => a * b;
print(operation(4, 5));
}
void main(){
sum();
}
7)
int max(int a, int b){
int maxx = 0;
if(a>b){
maxx = a;
}
else if(a<b){
maxx = b;
}
return maxx;
}
void sum(){
Function operation = (a, b) => max(a,b);
print(operation(6, 4));
}
void main(){
sum();
}
Download