Предмет: Информатика, автор: Diavolhhhh

Хотя-бы 1 задание С# Forms
Завдання №3. Сума двох перших цифр заданого чотиризначного числа дорівнює сумі двох його останніх цифр. Завдання №4. Сума цифр даного тризначного числа N є парним числом. Завдання №5. Квадрат заданого тризначного числа дорівнює кубу суми цифр цього числа.

Ответы

Автор ответа: asilvejstruk
1

Task 3:

private void btnCheck_Click(object sender, EventArgs e)

{

   int fourDigitNum = int.Parse(txtFourDigitNum.Text);

   int firstTwoSum = (fourDigitNum / 1000) + (fourDigitNum % 1000 / 100);

   int lastTwoSum = (fourDigitNum % 100 / 10) + (fourDigitNum % 10);

   if (firstTwoSum == lastTwoSum)

       MessageBox.Show("The sum of the first two digits is equal to the sum of the last two digits.");

   else

       MessageBox.Show("The sum of the first two digits is not equal to the sum of the last two digits.");

}

Task 4:

private void btnCheck_Click(object sender, EventArgs e)

{

   int threeDigitNum = int.Parse(txtThreeDigitNum.Text);

   int digitSum = (threeDigitNum / 100) + (threeDigitNum % 100 / 10) + (threeDigitNum % 10);

   if (digitSum % 2 == 0)

       MessageBox.Show("The sum of the digits is an even number.");

   else

       MessageBox.Show("The sum of the digits is an odd number.");

}

Task 5:

private void btnCheck_Click(object sender, EventArgs e)

{

   int threeDigitNum = int.Parse(txtThreeDigitNum.Text);

   int digitSum = (threeDigitNum / 100) + (threeDigitNum % 100 / 10) + (threeDigitNum % 10);

   int square = threeDigitNum * threeDigitNum;

   int cube = digitSum * digitSum * digitSum;

   if (square == cube)

       MessageBox.Show("The square of the number is equal to the cube of the sum of its digits.");

   else

       MessageBox.Show("The square of the number is not equal to the cube of the sum of its digits.");

}

Похожие вопросы
Предмет: Алгебра, автор: 0littlesunnysun0