Skip to content

Instantly share code, notes, and snippets.

@gcs-abdulwahab
Created September 23, 2022 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gcs-abdulwahab/055ef00f16b2a9b39e7b531ad618272f to your computer and use it in GitHub Desktop.
Save gcs-abdulwahab/055ef00f16b2a9b39e7b531ad618272f to your computer and use it in GitHub Desktop.
Finding Max using Loop while/For Loop
#include <iostream>
using namespace std;
int main() {
int a[10] = {1 ,2 ,3 ,5 , 3 , 1};
int max = a [0];
for (int i = 1; i < 5; ++i) {
if ( a[i] > max )
max = a[i];
}
cout << max <<" is the greatest";
return 0;
}
@gcs-abdulwahab
Copy link
Author

@manahilkhalid725 : using loop finding the Max

@gcs-abdulwahab
Copy link
Author

@manahilkhalid725 in line #10 It is in the scope of if
but unlike python it is not because of its indentation
but in c++ as discussed the next line is in the scope of if by default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment