Tospshiriqlarni bajarishda funksiyadan foydalanish zarur



Download 19,32 Kb.
Sana27.01.2023
Hajmi19,32 Kb.
#903738
Bog'liq
Tospshiriqlarni bajarishda funksiyadan foydalanish zarur


TOSPSHIRIQLARNI BAJARISHDA FUNKSIYADAN FOYDALANISH ZARUR.
Topshiriqlar

  1. Uch xonali son berilgan. Berilgan sonning raqamlari yig‘indisini topuvchi dastur tuzing.

    Input:

    Output:

    N kiriting: 867

    21

  2. To‘rt xonali son berilgan. Berilgan sonning raqamlari ko‘paytmasini topuvchi dastur tuzing.

    Input:

    Output:

    N kiriting: 4368

    576

  3. To‘g‘ri burchakli uchburchakning katetlari berilgan. Berilgan uchburchakning medianasini topuvchi dastur tuzing (Yaxlitlashda format() dan foydalaning).

    Input:

    Output:

    b,c ni kiritng: 5,6

    15.25

  4. Uchburchakning tomonlari berilgan. Uning a tomoniga tushuvchi medianasini topuvchi dastur tuzing (Yaxlitlashda format() dan foydalaning).

    Input:

    Output:

    b,c ni kiritng: 7,5,9

    6.38

  5. Shar radiusi berilgan. Uning hajmini topuvchi dastur tuzing (Yaxlitlashda format() dan foydalaning).

Input:

Output:

r ni kiriting: 7.5

31.42




  1. Uch xonali son berilgan. Berilgan sonning raqamlari yig‘indisini topuvchi dastur tuzing.

#include

// Function prototype
int sumOfDigits(int);

int main() {


int number;

// Get the three-digit number from the user


std::cout << "Enter a three-digit number: ";
std::cin >> number;

// Print the result


std::cout << "The sum of the digits is: " << sumOfDigits(number) << std::endl;

return 0;


}

// Function definition


int sumOfDigits(int n) {
int sum = 0;

// Calculate the sum of the digits


sum += n % 10;
n /= 10;
sum += n % 10;
n /= 10;
sum += n % 10;

return sum;


}


  1. To‘rt xonali son berilgan. Berilgan sonning raqamlari ko‘paytmasini topuvchi dastur tuzing.

#include

// Function prototype


int productOfDigits(int);

int main() {


int number;

// Get the four-digit number from the user


std::cout << "Enter a four-digit number: ";
std::cin >> number;

// Print the result


std::cout << "The product of the digits is: " << productOfDigits(number) << std::endl;

return 0;


}

// Function definition


int productOfDigits(int n) {
int product = 1;
// Calculate the product of the digits
product *= n % 10;
n /= 10;
product *= n % 10;
n /= 10;
product *= n % 10;
n /= 10;
product *= n % 10;

return product; }





  1. To‘g‘ri burchakli uchburchakning katetlari berilgan. Berilgan uchburchakning medianasini topuvchi dastur tuzing (Yaxlitlashda format() dan foydalaning).

#include


#include

// Function prototype


int median(int, int, int);

int main() {


int side1, side2, side3;

// Get the lengths of the triangle's sides from the user


std::cout << "Enter the lengths of the sides of the triangle: ";
std::cin >> side1 >> side2 >> side3;

// Print the result


std::cout << "The median of the triangle is: " << median(side1, side2, side3) << std::endl;

return 0;


}

// Function definition


int median(int a, int b, int c) {
int median;

// Find the median of the triangle


if (a > b && a > c) {
median = round(sqrt(b*b + c*c));
} else if (b > a && b > c) {
median = round(sqrt(a*a + c*c));
} else {
median = round(sqrt(a*a + b*b));
}

return median;


}


  1. Uchburchakning tomonlari berilgan. Uning a tomoniga tushuvchi medianasini topuvchi dastur tuzing (Yaxlitlashda format() dan foydalaning).

#include


#include
#include

using namespace std;

// Function prototype
double find_median_on_side_a(double a, double b, double c);

int main() {


// Test the function
cout << fixed << setprecision(2); // Set output to 2 decimal places
cout << find_median_on_side_a(3, 4, 5) << endl; // Output: "4.47"
cout << find_median_on_side_a(5, 12, 13) << endl; // Output: "9.00"
return 0;
}

// Function definition


double find_median_on_side_a(double a, double b, double c) {
// Find the length of the median that falls on side a
// using the formula:
// median = sqrt((2*b^2 + 2*c^2 - a^2)/4)
double median = sqrt((2*b*b + 2*c*c - a*a)/4);
// Return the length of the median
return median;
}


  1. Shar radiusi berilgan. Uning hajmini topuvchi dastur tuzing (Yaxlitlashda format() dan foydalaning).

#include


#include
#include

using namespace std;


// Function prototype


double find_size_of_sphere(double radius);

int main() {


// Test the function
cout << fixed << setprecision(2); // Set output to 2 decimal places
cout << find_size_of_sphere(2) << endl; // Output: "33.51"
cout << find_size_of_sphere(3) << endl; // Output: "113.10"
return 0;
}

// Function definition


double find_size_of_sphere(double radius) {
// Find the size of the sphere using the formula:
// size = 4/3 * pi * radius^3
const double PI = 3.14159265;
double size = 4.0/3.0 * PI * radius * radius * radius;
// Return the size of the sphere
return size;
}

Download 19,32 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish