Program to calculate Variance of first N Natural Numbers | C ++ Program to implement the above approach ; Function to calculate Variance of first N natural numbers ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; long double find_Variance ( int n ) { long long int numerator = n * n - 1 ; long double ans = ( numerator * 1.0 ) / 12 ; return ans ; } int main ( ) { int N = 5 ; cout << fixed << setprecision ( 6 ) << find_Variance ( N ) ; }