You are here:

C++/programming

Advertisement


Question
write a program that lets the user enter 50 elements in an array whose data type is integer. Locate the smallest and largest elements and display their corresponding value and location.

Answer
Hello,

do not forget to add your time.h header to this when you finally flesh it :)

code


int arr[50];
int bigValue;
int pos1, pos2;
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);


for (int i = 0; i<50; i++)
{
   arr[i] = rand();
}

//find the smallest and largest numbers..
int smallValue = arr[0];

for(int i=0;i<50;i++)
   {
       if(array[i]>bigValue){
       bigValue=array[i];
        pos1 = i;
       }     
   }
  
for(int i=0;i<50;i++)
   {
       if(array[i]<temp){
       smallValue=array[i];
       pos2 = i;
     }
   }
 

cout<<"the biggest value is"<<bigValue<<"in position"<<pos1<<endl;
cout<<"the smallest value is"<<smallValue<<"in position"<<pos2<<endl;

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


henry

Expertise

I can confidently answer any question both basic and advanced in C++. Areas like templates, algorithms, Gui and design patterns are of interest to me. i will not answer questions about web programming.

Experience

I have a 3- year- work experience in software Engineering.

Education/Credentials
I am a bachelor of Engineering graduate

©2016 About.com. All rights reserved.