Sum of both diagonals of a spiral odd | C ++ program to find sum of diagonals of spiral matrix ; function returns sum of diagonals ; as order should be only odd we should pass only odd - integers ; Driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int spiralDiaSum ( int n ) { if ( n == 1 ) return 1 ; return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) ) ; } int main ( ) { int n = 7 ; cout << spiralDiaSum ( n ) ; return 0 ; }