Console.WriteLine("牙膏5元,牙刷2元,肥皂3元,100元买这三种恰好花光"); int a1 = 0, b1 = 0, c1 = 0, sum = 0; for (int a = 0; a <= 20; a++) { a1 = 5 * a; for (int b = 0; b <= 50; b++) { b1 = 2 * b; for (int c = 0; c < 33; c++) { c1 = 3 * c; if (a1 + b1 + c1 == 100) { sum += 1; Console.WriteLine("买牙膏"+a+"支,牙刷"+b+"支,肥皂"+c+"块!"); } } } } Console.WriteLine("一共有"+sum+"种可能性!");
时间: 2024-11-08 22:30:58