1. Problem Description: Position of the Maximum Number
Code is as follows:
#include <bits/stdc++.h>using namespace std;int main(){int n; cin >> n;int a[n+7] = {0};for(int i=1;i<=n;i++){ cin >> a[i]; }int max_v = 1;for(int i=2;i<=n;i++){if(a[i]>a[max_v]){ max_v = i; } } cout << max_v; }
Output is as follows:
2. Problem Description: Difference Between Maximum and Minimum Values
Code is as follows:
#include <bits/stdc++.h>using namespace std;int main(){int n; cin >> n;int a[n+7] = {0};for(int i=1;i<=n;i++){ cin >> a[i]; }int max_v = a[1],min_v = a[1];for(int i=2;i<=n;i++){if(a[i]>max_v){ max_v = a[i]; }if(a[i]<min_v){ min_v = a[i]; } } cout << max_v - min_v; }
Output is as follows:
Implemented using sort
3. Problem Description: Sum of Odd and Even Indexed Elements
Code is as follows:
#include <bits/stdc++.h>using namespace std;int main(){int n; cin >> n;int a[n+7] = {0};for(int i=0;i<n;i++){ cin >> a[i]; }int js = 0,os = 0;for(int i=0;i<n;i++){if(i%2 == 0){ os+=a[i]; }else{ js+=a[i]; } } cout << os << " " << js;}
Output is as follows: