The basics of programming in c++ for beginners

Tasks: Data types, variables and constants

Here are collected the task to the article Data types, variables and constants. Try to solve problems on their own and only need to look at the decision. So you will learn much faster programming fundamentals.

1. Declare variables with which you can calculate the total amount of the purchase of several products. For example a chocolate bar, coffee and packets of milk.

2. Declare three variables of type int, and the first to assign a numeric value, the second variable is the first variable increased by 3, and the third variable is equal to the sum of the first two.

3. Declare variables, to count the total number of objects for the table. for example cups, the same number of saucers and spoons.

126 thoughts on “Tasks: Data types, variables and constants

  1. #include

    int main() {
    using namespace std;

    int cups;
    int spoon;
    int saucers;

    cout << "Введите кол-во чашек: " <> cups;

    spoon = saucers = cups;

    float sum;

    sum = (cups + spoon + saucers);

    cout << "Общее кол-во предметов: " << sum << endl;

    return 0;
    }

  2. #include

    using std::cout;

    void fast_sort (int * arr, int first, int last){
    if (first < last){
    int l_ = first;
    int _r = last;
    int midl = arr[(first + last) / 2];

    do{
    while (arr[l_] midl)
    _r–;

    if (l_ <= _r){
    int point = arr[l_];
    arr[l_] = arr[_r];
    arr[_r] = point;
    l_++;
    _r–;
    }
    }while (l_ <= _r);

    if (first l_)
    fast_sort(arr, l_, last);
    }
    }

    int main(){
    int zxc[] = {123, 23, 444, 213, 111, 44, -9};
    fast_sort(zxc, 0, (sizeof(zxc) / 4)-1);

    for (int i : zxc)
    cout << i << " ";
    }

  3. #include

    using std::cout;

    void fast_sort (int * arr, int first, int last){
    if (first < last){
    int l_ = first;
    int _r = last;
    int midl = arr[(first + last) / 2];

    do{
    while (arr[l_] midl)
    _r–;

    if (l_ <= _r){
    int point = arr[l_];
    arr[l_] = arr[_r];
    arr[_r] = point;
    l_++;
    _r–;
    }
    }while (l_ <= _r);

    if (first l_)
    fast_sort(arr, l_, last);
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *