c++程序—五只小猪称体重
#include<iostream> using namespace std; #include<string> #include<ctime> int main() { //五只小猪称体重 int arr[5] = { 300,350,200,400,250 }; int min ; int n=0; min = arr[0]; for (int i = 0; i < 5; i++) { if (arr[i] < min) { min = arr[i]; n = i; } } cout << "第" << n + 1 << "只小猪最轻" << endl; cout << "体重最轻的小猪为:" << min << endl; system("pause"); return 0; }