Thursday, July 30, 2009

Can i have the example of an c++ programming in array?that display the smallest number.?

the program should display the smallest number..

Can i have the example of an c++ programming in array?that display the smallest number.?
probably not the best example but:-





#include%26lt;iostream%26gt;





int main()


{


int myarray[10] = {4,8,35,64,78,2,35,25,97,2};


int highest = NULL;


for(int i=0; i%26lt;sizeof myarray/4; i++)


{


if(myarray[i] %26lt; highest || highest == NULL)


{


highest = myarray[i];


}


}


std::cout %26lt;%26lt; "The smallest value in myarray is = " %26lt;%26lt; highest %26lt;%26lt; std::endl;


return 0;


}
Reply:int main()





{





int i;





float small, balance[n]={100.00,40.00,-30.00,400.00,6...





small = balance[0];





//loop for displaying array content....





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





cout%26lt;%26lt;balance[i]%26lt;%26lt;" ";











//Another loop do the array element comparing...





for(i=1; i%26lt;n; i++) //check until condition i = n





{





if(small %26gt; balance[i])





small = balance[i];





}





cout%26lt;%26lt;"\nSearching..."%26lt;%26lt;endl;





//display the result...





cout%26lt;%26lt;"The smallest value in the given array is = "%26lt;%26lt;small%26lt;%26lt;endl;





system("pause");





return 0;





}


balance is just the name. u can remove it..


No comments:

Post a Comment