Showing posts with label array index. Show all posts
Showing posts with label array index. Show all posts

Sunday, August 23, 2015

Biggest Number in Array and its Position

Q. 94. Program to input 'n' numbers into an array. Find the biggest among them and print its position (array index position + 1).


Copy Code:

#include <iostream>

using namespace std;

int main()

{

  int a[25], n, i, bg = 0, pn = 0; 

  cout << " How many numbers can you provide? -> " ;

  cin >> n ;

  cout << "Enter " << n << " numbers \n" ;

  

  for ( i = 0 ; i < n ; ++i)

  {

     cin >> a [ i ] ; 

     if (a[ i ] > bg)

      {

         bg = a[ i ] ; pn = i ;

      }

  }

  cout << "Biggest Number is -> " << bg << " at position " << pn+1;

  return 0;

}