Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Cpp program to find the largest integer on an array and describing this precisely.
- // created on June, 2016
- // Author: fueanta
- #include <iostream>
- using namespace std;
- int main(){
- int x;
- cout << "How many numbers do you want to store?\n\nInput: ";
- cin >> x;
- int arr[x];
- cout << endl;
- for (int i=0;i<x;i++){
- cout << "\nElement No(" << i+1 <<") : ";
- cin >> arr[i];
- }
- int maxima=arr[0];
- for (int i=1;i<x;i++){
- if (arr[i]>maxima){
- maxima=arr[i];
- }
- }
- int counta1=0,counta2=0;
- //cout << "The largest value you have given is "<< maxima << endl;
- for (int i=0;i<x;i++){
- if (arr[i]==maxima){
- counta1++;
- }
- }
- cout << "\n\nElement No -> ";
- for (int i=0;i<x;i++){
- if (arr[i]==maxima){
- cout <<i+1;
- counta2++;
- if (counta2!=counta1){
- if (counta2!=(counta1-1)){
- cout << ", ";
- }
- else{
- cout << " and ";
- }
- }
- else{
- cout << " ";
- }
- }
- }
- if (counta1==1){
- cout << "has ";
- }
- else{
- cout << "have ";
- }
- cout << "the largest value: " << maxima << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment