Harfli ifodalar :: Yechimlar
Masala A
\(\frac{x^2-4}{x-2}\) ifoda qisqartirilsa \(x+2\) ko‘rinishiga o‘tadi. Shuning uchun ham dastur kodlarida \(x+2\) ishlatilgan.
Kiritilgan x
qiymat uchun quyidagi y
ning qiymatini hisoblab, ekranga chiqaradigan dastur tuzing.
$$ y = x^3 - \frac{x^2-4}{x-2} - 5x + 50 $$
x
ning qiymat -100 dan 100 gacha.
y
ning qiymat
#include <stdio.h>
int main() {
int x;
scanf("%d", &x);
int y = x * x * x - (x + 2) - 5 * x + 50;
printf("%d", y);
return 0;
}
import math
import itboom
def main():
x = int(input())
y = x ** 3 - (x + 2) - 5 * x + 50
print(y)
if __name__ == '__main__':
main()
Masala B
Kiritilgan x
ning qiymatida quyidagi A
, B
, C
ifodalarning qaysi birining qiymati eng katta bo‘lsa shu ifoda harfini ekranga chiqaradigan dastur tuzing.
$$ A = x - 10\sin{x}$$
$$ B = x - 20\cos{x} $$
$$ C = \frac{x - 10\sin{x}}{10\cos{x}} + 1 $$
x
ning qiymat -100 dan 100 gacha
A
, B
, C
lardan eng qiymati eng kattasining harfi
#include <stdio.h>
#include <math.h>
int main() {
int x;
scanf("%d", &x);
float A = x - 10 * sin(x);
float B = x - 20 * cos(x);
float C = (x - 10 * sin(x)) / (10 * cos(x)) + 1;
if (A > B && A > C) {
printf("A");
} else if (B > A && B > C) {
printf("B");
} else {
printf("C");
}
return 0;
}
import math
import itboom
def main():
x = int(input())
A = x - 10 * math.sin(x);
B = x - 20 * math.cos(x);
C = (x - 10 * math.sin(x)) / (10 * math.cos(x)) + 1;
if A > B and A > C:
print("A");
elif B > A and B > C:
print("B");
else:
print("C");
if __name__ == '__main__':
main()
Masala C
Berilgan ifodaning qiymati kiritilgan y
ga teng bo‘ladinga x
ning qiymatini topadigan dastur tuzing.
$$ y = x^3 + x^2 + x + 1 $$
y
ning qiymati
Berilga ifodaning qiymati y
ga teng bo‘lishi mumkin bo‘lgan x
ning qiymati
#include <stdio.h>
#include <itboom.h>
int main() {
int y;
scanf("%d", &y);
for(int x = -1000; x <= 1000; x++) {
if (y == x * x * x + x * x + x + 1) {
printf("%d", x);
break;
}
}
return 0;
}
import math
import itboom
def main():
y = int(input())
for x in range(-1000, 1001):
if y == x ** 3 + x ** 2 + x + 1:
print(x)
break
if __name__ == '__main__':
main()
Masala D
Kiritilgan a
va b
lardan foydalanib, quyidagi ifodaning dasturlash tillarida yozilishini ekranga chiqaradigan dastur tuzing.
$$ ax^2+bx+5 $$
Bir qatorda a
, b
larning qiymatlari -5 dan 5 gacha.
Yuqoridagi ifodaning dasturlash tillarida yozilish shakli
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <itboom.h>
int main() {
// Kodni shu yerga yozing
int a, b;
scanf("%d %d", &a, &b);
if (a != 0) {
if (a == -1) {
printf("-");
} else if (a != 1) {
printf("%d*", a);
}
printf("x^2");
}
if (b != 0) {
if (b == -1) {
printf("-");
} else if (b == 1) {
if (a != 0) {
printf("+");
}
} else {
if (a != 0 && b > 0) {
printf("+");
}
printf("%d*", b);
}
printf("x");
}
if (a != 0 || b != 0) {
printf("+");
}
printf("5");
return 0;
}
import math
import itboom
def main():
a, b = map(int, input().split())
expr = ""
if a != 0:
if a == -1:
expr += "-"
elif a != 1:
expr += str(a) + "*"
expr += "x^2"
if b != 0:
if b == -1:
expr += "-"
elif b == 1:
if expr:
expr += "+"
elif b != 1:
if expr and b > 0:
expr += "+"
expr += str(b) + "*"
expr += "x"
if expr:
expr += "+"
expr += "5"
print(expr)
if __name__ == '__main__':
main()
Masala E
Ishlash algoritmi: kiritilgan ikki xonali sonning birinchisidan ikkinchisining ASCII kodi ayiriladi va qolgan natijaga 49 qo’shiladi.
Agar ikkalasi bir xil qiymat bo‘lsa, ayirma natija 0 ga teng bo‘ladi va 49 qo‘shganda ASCII jadvalidagi 1 ga mos tushadi. Aks holda 1 dan boshqa belgi/sonlar ekranga chiqariladi.
Pythondagi qisqa kodi (24 kiritilgan holat uchun):
chr(ord("2") - ord("4")) + 49)
Kiritilgan ikki xonali son 11 ga karrali bo‘lsa 1
, aks holda xohlagan belgini ekranga chiqaradigan dasatur tuzing
Ikki xonali son
Agar 11 ga karrali bo‘lsa 1
aks holda xohlagan belgi
,>,[<->-]++++++++[<++++++>-]<+.