คุณสามารถแก้ไขของคุณฟังก์ชันต้องใช้เวลา 2 ข้อโต้แย้งแทนที่จะเป็น 1 ที่แสดงทางด้านล่างนี้ ข้อโต้แย้งแรก corresponds จะเริ่มจำและครั้งที่สอง corresponds ต้องตอนจบหมายเลข
#include <iostream>
using namespace std;
//function uniquePairs takes 2 arguments now instead of just 1
void uniquePairs(int startingNumber, int endingNumber) {
int k = 0;
for (int i = startingNumber; i <= endingNumber; ++i) {
for (int j = startingNumber + k; j<= endingNumber; j++) {
cout << "(" << i << "," << j << ")" << endl;
}
++k;
}
}
int main() {
int startingNumber, endingNumber;
std::cout<<"Enter startingNumber: "<<std::endl;
std::cin >> startingNumber;
std::cout<<"Enter endingNumber: "<<std::endl;
std::cin >> endingNumber;
//call the function while passing the 2 input numbers
uniquePairs(startingNumber,endingNumber);
return 0;
}
การส่งออกของที่อยู่เหนือโปรแกรมสำหรับ inputs startingNumber =1
แล้ว endingNumber = 5
คือ:
Enter startingNumber:
1
Enter endingNumber:
5
(1,1)
(1,2)
(1,3)
(1,4)
(1,5)
(2,2)
(2,3)
(2,4)
(2,5)
(3,3)
(3,4)
(3,5)
(4,4)
(4,5)
(5,5)
การส่งออกของที่อยู่เหนือโปรแกรมจะได้เห็น มาที่นี่. ยังมองดู ทำไมฉันต้องไม่ใช่#รวม<บิต/stdc++.h>?.
#include<iostream>
ในดั้งเดิมของฉันตอบคำถาม แต่แล้วฉันทำบางอย่างแก้ไขและอีกครั้ง pasted รหัสจากเว็บเบราว์เซอร์ภายนอกเว็บไซต์ซึ่งเรื่องนี้#include<bits/stdc++.h>
. ถ้าคุณเห็นแก้ไขประวัติศาสตร์ของคำตอบของฉันคุณจะเห็นว่าฉันมี#include<iostream>
. ฉันต้องเพิ่มเชื่อมโยงไปยัง"ทำไมไม่ใช้มันbits/stdc++.h
"สำหรับปฏิบัติการเดี๋ยวนี้