17 September 2018

C++ program on passing array and its size as parameters

//program on passing array and its size as parameters
//displays the index value of minimum element
#include<iostream>
using namespace std;
int k;
int minindex(int a[],int n)
    {
    int mini=a[0];
    for(int i=0;i<n;i++)
       {
         if(mini>a[i])
        {
                   mini=a[i];
               k=i;//Storing index value
        }
      
        }
 return k;// Returning index value
    }
  int main()
    {
    int a[20],n,min;
    cout<<"How many numbers you want to enter"<<endl;
    cin>>n;
    cout<<"Enter a list of "<<n<<" integers"<<endl;
    for(int i=0;i<n;i++)
      {
        cin>>a[i];
      }
    min=minindex(a,n);//Passing(as parameters)array and its size
    cout<<"Minimum element is present at index "<<min;
    cout<<endl;
   return 0;
    }

No comments:

Post a Comment

To convert from Upper case to lowercase(A to a)

//converting from Upper to lower(A to a) import java.util.*; class case { public static void main(String args[]) { System.out.pr...