यहां हम देखेंगे कि N फैक्टोरियल के योग का इकाई स्थान अंक कैसे प्राप्त करें। यदि N=3 है, तो योग प्राप्त करने के बाद: 1! + 2! + 3! = 9, यह परिणाम होगा। N=4 के लिए: 1! + 2! + 3! + 4! = 33, इसलिए इकाई स्थान 3 है। यदि हम इसे स्पष्ट रूप से देखें, तो N > 5 के फैक्टोरियल के लिए, इकाई स्थान 0 होता है, इसलिए 5 के बाद यह इकाई स्थान को बदलने में योगदान नहीं देगा। N=4 और अधिक के लिए, यह 3 होगा। हम इकाई स्थान के लिए एक चार्ट बना सकते हैं और उसका उपयोग प्रोग्राम में कर सकते हैं।
C++ उदाहरण
#include <iostream>
#include <cmath>
using namespace std;
double getUnitPlace(int n) {
int placeVal[5] = {-1, 1, 3, 9, 3};
if (n > 4) n = 4;
return placeVal[n];
}
int main() {
for (int i = 1; i < 10; i++) {
cout << "Unit place value of sum of factorials when N = " << i
<< " is: " << getUnitPlace(i) << endl;
}
return 0;
}
आउटपुट
Unit place value of sum of factorials when N = 1 is: 1 Unit place value of sum of factorials when N = 2 is: 3 Unit place value of sum of factorials when N = 3 is: 9 Unit place value of sum of factorials when N = 4 is: 3 Unit place value of sum of factorials when N = 5 is: 3 Unit place value of sum of factorials when N = 6 is: 3 Unit place value of sum of factorials when N = 7 is: 3 Unit place value of sum of factorials when N = 8 is: 3 Unit place value of sum of factorials when N = 9 is: 3