#include #include // for rand and srand



Yüklə 36,58 Kb.
tarix07.01.2024
ölçüsü36,58 Kb.
#203874
dasturlash111


MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALAR UNIVERSITETI


Dasturlash 1 fanidan

Bajardi : Xolmamatov Diyorbek


Tekshirdi : Normominov Akbar

#include
#include // for rand() and srand()
#include // for time()

int main() {
const int arraySize = 12;
int originalArray[arraySize];

// Fill the array with random integers
srand(static_cast(time(0)));
for (int i = 0; i < arraySize; ++i) {
originalArray[i] = rand() % 100; // Random integers between 0 and 99
}

// Display the original array
std::cout << "Asl massiv: ";
for (int i = 0; i < arraySize; ++i) {
std::cout << originalArray[i] << " ";
}
std::cout << std::endl;

// Calculate the middle arithmetic
int sum = 0;
for (int i = 0; i < arraySize; ++i) {
sum += originalArray[i];
}
double middleArithmetic = static_cast(sum) / arraySize;

// Replace the 5th element with the middle arithmetic value
originalArray[4] = static_cast(middleArithmetic);

// Display the modified array
std::cout << "O'zgartirilgan massiv: ";
for (int i = 0; i < arraySize; ++i) {
std::cout << originalArray[i] << " ";
}
std::cout << std::endl;

return 0;
}



#include

int main() {
const int arraySize = 8;
int originalArray[arraySize];

// Input array with two-digit numbers
std::cout << "8 ta ikki xonali butun sonlar qatorini kiriting:" << std::endl;
for (int i = 0; i < arraySize; ++i) {
std::cout << "Element " << i + 1 << ": ";
std::cin >> originalArray[i];

// Validate that the entered number is two-digit
while (originalArray[i] < 10 || originalArray[i] > 99) {
std::cout << "Ikki xonali raqamni kiriting." << std::endl;
std::cout << "Element " << i + 1 << ": ";
std::cin >> originalArray[i];
}
}

// Display the original array
std::cout << "Original array: ";
for (int i = 0; i < arraySize; ++i) {
std::cout << originalArray[i] << " ";
}
std::cout << std::endl;

// Create a new array with individual digits as separate elements
int newArray[arraySize * 2]; // Twice the size to accommodate individual digits

for (int i = 0; i < arraySize; ++i) {
newArray[i * 2] = originalArray[i] / 10; // Tens digit
newArray[i * 2 + 1] = originalArray[i] % 10; // Units digit
}

// Display the new array
std::cout << "Individual raqamlarga ega yangi massiv: ";
for (int i = 0; i < arraySize * 2; ++i) {
std::cout << newArray[i] << " ";
}
std::cout << std::endl;

return 0;
}



#include
#include

int binaryToDecimal(int binaryNumber) {
int decimalNumber = 0, i = 0, remainder;
while (binaryNumber != 0) {
remainder = binaryNumber % 10;
binaryNumber /= 10;
decimalNumber += remainder * pow(2, i);
++i;
}
return decimalNumber;
}

int decimalToOctal(int decimalNumber) {
int octalNumber = 0, i = 1;
while (decimalNumber != 0) {
octalNumber += (decimalNumber % 8) * i;
decimalNumber /= 8;
i *= 10;
}
return octalNumber;
}

int main() {
int binaryNumber;

// Input binary number
std::cout << "Ikkilik raqamni kiriting: ";
std::cin >> binaryNumber;

// Convert binary to decimal
int decimalNumber = binaryToDecimal(binaryNumber);

// Convert decimal to octal
int octalNumber = decimalToOctal(decimalNumber);

// Display the result
std::cout << "Ekvivalent sakkizlik son: " << octalNumber << std::endl;

return 0;
}


Yüklə 36,58 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin