Answer to Question #209122 in C++ for shahil

Question #209122

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}


1
Expert's answer
2021-06-21T01:59:22-0400
#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;
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS