संख्याओं 'एन' की एक सरणी के साथ दिया गया है और कार्य एपी में तीन यादृच्छिक रूप से चुनी गई संख्याओं की संभावना खोजना है।
उदाहरण
Input-: arr[] = { 2,3,4,7,1,2,3 }
Output-: Probability of three random numbers being in A.P is: 0.107692
Input-:arr[] = { 1, 2, 3, 4, 5 }
Output-: Probability of three random numbers being in A.P is: 0.151515 नीचे दिए गए कार्यक्रम में उपयोग किया गया दृष्टिकोण इस प्रकार है -
- सकारात्मक पूर्णांकों की सरणी इनपुट करें
- सरणी के आकार की गणना करें
-
तीन यादृच्छिक संख्याओं के AP में होने की प्रायिकता ज्ञात करने के लिए नीचे दिए गए सूत्र को लागू करें
3 एन / (4 (एन * एन) - 1)
- परिणाम प्रिंट करें
एल्गोरिदम
Start
Step 1-> function to calculate the probability of three random numbers be in AP
double probab(int n)
return (3.0 * n) / (4.0 * (n * n) - 1)
Step 2->In main()
declare an array of elements as int arr[] = { 2,3,4,7,1,2,3 }
calculate size of an array as int size = sizeof(arr)/sizeof(arr[0])
call the function to calculate probability as probab(size)
Stop उदाहरण
#include <bits/stdc++.h>
using namespace std;
//calculate probability of three random numbers be in AP
double probab(int n) {
return (3.0 * n) / (4.0 * (n * n) - 1);
}
int main() {
int arr[] = { 2,3,4,7,1,2,3 };
int size = sizeof(arr)/sizeof(arr[0]);
cout<<"probability of three random numbers being in A.P is : "<<probab(size);
return 0;
} आउटपुट
Probability of three random numbers being in A.P is: 0.107692