githubEdit

Preliminaries (basics)

2.1 Largest element in array

Using goto with c++,

#include <iostream>
using namespace std;

void LargestElementInArray(int DATA[], int N)
{
    int K = 0, LOC = 0, MAX = DATA[0];
increment_counter:
    K = K + 1;
    if (K == N)
    {
        cout << "LOC = " << LOC << ", MAX = " << MAX << "\n";
        return;
    }
    if (MAX < DATA[K])
    {
        LOC = K;
        MAX = DATA[K];
    }
    goto increment_counter;
}

int main()
{
    int DATA[] = {3, 5, 9, 2};
    int N = sizeof(DATA) / sizeof(int);
    LargestElementInArray(DATA, N);
    return 0;
}

2.2 Quadratic equation

2.3 Largest element in array (while loop)

Same code as 2.1 but this time with while loop. Steps are as described as DS textbook (SEYMOUR LIPSCHUTZ)

Last updated

Was this helpful?