write a full c++ programto find the smallest value amongst the following numbers {10,98,87,16,88,46,100} and display the results in terms of positive /index of smallest value and the smallest values itself { hint use arrays}
#include <iostream>
#include <string>
using namespace std;
int main(){
int numbers[]={10,98,87,16,88,46,100};
int indexSmallestValue=0;
int smallestValue=numbers[0];
int size=sizeof(numbers)/sizeof(numbers[0]);
for(int i=1;i<size;i++){
if(numbers[i]<smallestValue){
indexSmallestValue=i;
smallestValue=numbers[i];
}
}
//display the results in terms of positive /index of smallest value and the smallest values itself
cout<<"Numbers: \n";
for(int i=0;i<size;i++){
cout<<numbers[i]<<" ";
}
cout<<"\n\nThe index of smallest value: "<<indexSmallestValue<<"\n";
cout<<"The smallest value: "<<smallestValue<<"\n\n";
system("pause");
return 0;
}
Comments
Leave a comment