Saturday, May 22, 2010

This is a c++ program for the smallest element in array. Pls write the code how it will be for biggest element

#include %26lt;iostream%26gt;


using namespace std;


int Min(int n, int a[100]);


int najmal;


int main()


{


int n, a[100], najmal;


cout%26lt;%26lt;"Vnesete go n: ";


cin%26gt;%26gt;n;


cout%26lt;%26lt;"Vnesete gi elementite na nizata: ";


for (int i=0; i%26lt;n; i++)


cin%26gt;%26gt;a[i];


najmal=Min (n-1, a);


cout%26lt;%26lt;"Najmal element e "%26lt;%26lt;najmal%26lt;%26lt;endl;


return 0;


}


int Min (int n, int a[])


{


if (n==0)


return a[0];


else


{


najmal=Min(n-1,a);


if (a[n]%26lt;najmal)


return a[n];


else


return najmal;


}


}

This is a c++ program for the smallest element in array. Pls write the code how it will be for biggest element
Make a copy of Min, change the name to Max (and change the recursive call as well), and change the "%26lt;" to "%26gt;" in the logic.
Reply:i dont know man


No comments:

Post a Comment