PetraAI / Additional algorithm 21.cpp
PetraAI's picture
Upload 136 files
3da5d57
//Paul A. Gagniuc. An Introduction to Programming Languages: Simultaneous Learning in Multiple Coding Environments. Synthesis Lectures on Computer Science. Springer International Publishing, 2023, pp. 1-280.
//Additional algorithm 21. Demonstrates the implementation of conditional statements on array variables. Three elements of an array variable (A) are declared and filled with values. A condition triggers a statment to increment the value of the last element of the array (ie. A[2]), only if the value of the first element (ie. A[0]) is less than the value of the second element (ie. A[1]), otherwise a decrement is applied to the value of the last element of the array. Note that the source code is in context and works with copy/paste.
#include <iostream>
using namespace std;
int main()
{
int A[] = {1, 2, 3};
if(A[0] < A[1]){A[2] += 1;}
cout<<"A[2]="<<A[2];
return 0;
}