Created
September 23, 2022 07:45
-
-
Save gcs-abdulwahab/055ef00f16b2a9b39e7b531ad618272f to your computer and use it in GitHub Desktop.
Finding Max using Loop while/For Loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
@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
@manahilkhalid725 : using loop finding the Max