“CPP #include ""” Kode Jawaban

C

#include <iostream>

int main() {
  std::cout << "Hello, World!\n";
}
PrototypeCodec

c

God's language
slohobo

CPP

// M.MUZAMMIL        01-132202-021
#include <iostream>
using namespace std;
void shift(int *a, int size)
{
    int max = a[0], index, element;

    cout << "\nEnter element to insert by shifting before maximum value: ";
    cin >> element;

    for (int i = 0; i < size; i++)
    {
        if (a[i] > max)
        {
            max = a[i];
            index = i;
        }
    }

    for (int i = size; i >= index; i--)
    {
        a[i + 1] = a[i];
    }
    a[index] = element;
}
int sort(int *array, int size)
{
    for (int i = 0; i < size; i++)
    {
        for (int j = i + 1; j < size; j++)
        {
            if (array[j] < array[i])
            {
                int temp = array[i];
                array[i] = array[j];
                array[j] = temp;
            }
        }
    }
    return 0;
}

int median(int array[], int size)
{
    int med, n;
    if (size % 2 == 0)
    {
        med = size / 2;
        med = (med + (med + 1)) / 2;
        n = med;
    }
    else
    {
        med = (size - 1) / 2;
        n = med;
    }
    return n;
}

void deleteelementy(int *array, int size, int med)
{
    for (int i = med; i < size; i++)
    {

        array[i] = array[i + 1];
    }
}
int main()
{
    int choice;
    cout << "\t\t\<<< Menu >>>\nPress\n 1-->Question(1)\n2-->Question(2) :" << endl;
    cin >> choice;

    switch (choice)
    {
    case 1:
    {
        int size = 10;
        int *a = new int[10];
        cout << "Enter the elements..." << endl;
        cout << endl;
        for (int i = 0; i < size; i++)
        {
            cin >> a[i];
        }
        cout << " \nArray before inserting..." << endl;
        for (int i = 0; i < size; i++)
        {
            cout << a[i] << " ";
        }
        shift(a, size);
        cout << "\nArray after inserting..." << endl;
        for (int i = 0; i < size; i++)
        {
            cout << " " << a[i];
        }
        break;
    }

    case 2:
    {
        int size;
        cout << "enter size of array :" << endl;
        cin >> size;
        int *array = new int[size];
        for (int i = 0; i < size; i++)
        {
            cin >> array[i];
        }
        sort(array, size);
        cout << "\nSorted array ";
        for (int i = 0; i < size; i++)
        {
            cout << array[i];
        }
        int med = median(array, size);

        cout << "\nAfter deleting " << endl;
        deleteelementy(array, size, med);
        for (int i = 0; i < size - 1; i++)
        {
            cout << array[i] << " ";
        }
        delete[] array;

        break;
    }

    default:
        cout << "\n Invalid choice ...\n";
        break;
    }

    return 0;
}
Amused Aardvark

Jawaban yang mirip dengan “CPP #include ""”

Pertanyaan yang mirip dengan “CPP #include ""”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya