X, y haqiqiy va amal butun son berilgan. X va y sonlari ustiga arifmetik amallar bajaruvchi dastur tuzilsin. Amal quyidagi qiymatlarni qabul qiladi: 1-qo’shish, 2-ayirish, 3-bo’lish, 4-ko’paytirish
#include using namespace std;
int main()
{
int k;
float y;
cout << "k = ";
cin >> k;
if (sin(k) <= 0.2)
{
y = sqrt(k);
}
else if (sin(k) > 0.2)
{
y = 1 / sqrt(k);
}
cout << "y = " << y << endl;
}
2-TOPSHIRIQ Case12. X, Y haqiqiy va amal butun son berilgan. X va Y sonlari ustiga arifmetik amallar bajaruvchi dastur tuzilsin. Amal quyidagi qiymatlarni qabul qiladi: 1-qo’shish, 2-ayirish, 3-bo’lish, 4-ko’paytirish.
#include using namespace std;
int main()
{
int k;
float a, b, c, d;
int x, y;
cout << "x = ";
cin >> x;
cout << "y = ";
cin >> y;
for (int k = 1; k <= 4; k++)
{
switch (k)
{
case 1:
cout << "x + y = " << x + y << endl;
break;
case 2:
cout << "x - y = " << x - y << endl;
break;
case 3:
cout << "x / y = " << x / y << endl;
break;
case 4:
cout << "x * y = " << x * y << endl;
break;
default:
break;
}
}
}
3-TOPSHIRIQ
#include
using namespace std;
int main()
{
int l1, l2, s, a;
cout << " Butun sonlar kiriting (0 qiymat berilsa kiritish to'xtatiladi) -> ";
cin >> a;
while (a != 0)
{
if (a % 5 == 0)
l1++;
if (a % 7 == 0)
l2++;
if (a < 0)
s += a;
cin >> a;
}
cout << "ketma-ketlikda 7 ga karrali sonlar soni : " << l2 << endl;
cout << "ketma-ketlikda 5 ga karrali sonlar soni : " << l1 << endl;
cout << "ketma-ketlikda manfiy sonlar yig'indisi : " << s << endl;
return 0;
}
4-TOPSHIRIQ
#include
using namespace std;
int main()
{
float x[] = {5.4, 2.3, -4.6, 7.8, -3.4, 25.6};
float y[6];
int k = 0;
for (int i = 6 - 1; i >= 0;)
{
y[k++] = x[i--];
}
cout << "x[] = ";
for (int i = 0; i < 6; i++)
{
cout << x[i] << " ";
}
cout << endl;
cout << "y[] = ";
for (int i = 0; i < 6; i++)
{
cout << y[i] << " ";
}
cout << endl;
}