Find solutions to your problems with the help of IDNLearn.com's knowledgeable users. Get prompt and accurate answers to your questions from our experts who are always ready to help.
Sagot :
Answer:
This solution is implemented in C++:
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
double termnum;
cout<<"Terminating number: ";
cin>>termnum;
double num;
vector<double>numbers;
cout<<"Number: ";
cin>>num;
while(num!=termnum){
numbers.push_back(num);
cout<<"Number: ";
cin>>num;
}
double smallest = numbers.at(0);
for(double x:numbers){
if(x < smallest){
smallest = x;
}
}
cout<<"The smallest is "<<smallest;
return 0;
}
Explanation:
This declares the terminating variable as double
double termnum;
The next italicized lines prompts user for terminating value
cout<<"Terminating number: ";
cin>>termnum;
This declares the user input variable as double
double num;
This declares vector of numbers as double
vector<double>numbers;
The next italicized lines prompts user for number
cout<<"Number: ";
cin>>num;
The following iteration is repeated until the terminating value equals the number supplies by the user
while(num!=termnum){
This pushes the number to a vector
numbers.push_back(num);
The italicized lines prompts user for another number
cout<<"Number: ";
cin>>num;
}
This declares and initializes variable smallest
double smallest = numbers.at(0);
The following for loop determines the smallest of the number set
for(double x:numbers){
if(x < smallest){
smallest = x;
}
}
This prints the smallest of the set
cout<<"The smallest is "<<smallest;
return 0;
Also: See attachment
We are happy to have you as part of our community. Keep asking, answering, and sharing your insights. Together, we can create a valuable knowledge resource. Thank you for visiting IDNLearn.com. We’re here to provide clear and concise answers, so visit us again soon.