4. Vector ni ga va ga bo`linadigan elementlarini ko`paytmasini sinusi tоpilsin
Download 0.52 Mb.
|
44 2-lab
1-topshiriq 14.Vector ni 2 ga va 5 ga bo`linadigan elementlarini ko`paytmasini sinusi tоpilsin #include #include #include int main() { std::vector double result = 1.0; for(int i = 0; i < v.size(); i++) { if(v[i] % 2 == 0 && v[i] % 5 == 0) { result *= v[i]; } } std::cout << "Result: " << sin(result)<< std::endl; return 0; } 2-topshiriq 8. a Vektorning k-elementidan boshlab b Vektor qo’shilib yangi с Vektor hosil qilinsin. #include #include using namespace std; int main() {
#include using namespace std; int main() { int n = 10; int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int sum = 0; int count = 0; for(int i = 0; i < n; i++) { if(a[i] % 2 == 0) // juft sonlarni aniqlab olish { sum += a[i]; // yig'indini hisoblash count++; // nechta son hisoblandigini saqlash } } if(count > 0) { float avg = (float)sum / count; // o'rta arifmetikni hisoblash cout << "Juft sonlar o'rtacha qiymati: " << avg << endl; } else { cout << "Massivda juft sonlar yo'q." << endl; } return 0; } Download 0.52 Mb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling